Skip to content

Commit

Permalink
fix(upload-client): send content-type header when uploading multipa…
Browse files Browse the repository at this point in the history
…rt (#461)

* fix(upload-client): send `content-type` header when uploading multipart

* chore(upload-client): use conditional assignment
  • Loading branch information
nd0ut authored Jan 20, 2023
1 parent e140644 commit 3a402a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/upload-client/src/api/multipartUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { MultipartPart } from './multipartStart'

import request from '../request/request.node'

import defaultSettings from '../defaultSettings'
import defaultSettings, { defaultContentType } from '../defaultSettings'
import { retryIfFailed } from '../tools/retryIfFailed'
import { SupportedFileInput } from '../types'
import { ComputableProgressInfo, ProgressCallback } from './types'

export type MultipartUploadOptions = {
publicKey?: string
contentType?: string
signal?: AbortSignal
onProgress?: ProgressCallback<ComputableProgressInfo>
integration?: string
Expand All @@ -28,6 +29,7 @@ export default function multipartUpload(
part: SupportedFileInput,
url: MultipartPart,
{
contentType,
signal,
onProgress,
retryThrottledRequestMaxTimes = defaultSettings.retryThrottledRequestMaxTimes,
Expand All @@ -42,7 +44,10 @@ export default function multipartUpload(
data: part,
// Upload request can't be non-computable because we always know exact size
onProgress: onProgress as ProgressCallback,
signal
signal,
headers: {
'Content-Type': contentType || defaultContentType
}
})
.then((result) => {
// hack for node ¯\_(ツ)_/¯
Expand Down
7 changes: 6 additions & 1 deletion packages/upload-client/src/uploadFile/uploadMultipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const uploadPart = (
url: string,
{
publicKey,
contentType,
onProgress,
signal,
integration,
Expand All @@ -57,6 +58,7 @@ const uploadPart = (
): Promise<MultipartUploadResponse> =>
multipartUpload(chunk, url, {
publicKey,
contentType,
onProgress,
signal,
integration,
Expand Down Expand Up @@ -121,9 +123,11 @@ export const uploadMultipart = async (
}
}

contentType ||= getContentType(file)

return multipartStart(size, {
publicKey,
contentType: contentType || getContentType(file),
contentType,
fileName: fileName || getFileName(file),
baseURL,
secureSignature,
Expand All @@ -147,6 +151,7 @@ export const uploadMultipart = async (
(url, index) => (): Promise<MultipartUploadResponse> =>
uploadPart(getChunk(index), url, {
publicKey,
contentType,
onProgress: createProgressHandler(parts.length, index),
signal,
integration,
Expand Down

0 comments on commit 3a402a3

Please sign in to comment.