Skip to content

Commit dda9228

Browse files
committed
fix(Uploader): Pass on customHeaders when creating chunked upload workspace
Signed-off-by: provokateurin <kate@provokateurin.de>
1 parent 5b79789 commit dda9228

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

__tests__/utils/upload.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ describe('Initialize chunks upload temporary workspace', () => {
7575
retries: 5,
7676
retryDelay: expect.any(Function),
7777
},
78+
headers: {},
7879
})
7980
})
8081

lib/uploader/uploader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export class Uploader {
493493
logger.debug('Initializing chunked upload', { file, upload })
494494

495495
// Let's initialize a chunk upload
496-
const tempUrl = await initChunkWorkspace(encodedDestinationFile, retries, this._isPublic)
496+
const tempUrl = await initChunkWorkspace(encodedDestinationFile, retries, this._isPublic, this._customHeaders)
497497
const chunksQueue: Array<Promise<void>> = []
498498

499499
// Generate chunks array

lib/utils/upload.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ export const getChunk = function(file: File, start: number, length: number): Pro
116116
* @param destinationFile The file name after finishing the chunked upload
117117
* @param retries number of retries
118118
* @param isPublic whether this upload is in a public share or not
119+
* @param customHeaders Custom HTTP headers used when creating the workspace (e.g. X-NC-Nickname for file drops)
119120
*/
120-
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false): Promise<string> {
121+
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false, customHeaders: Record<string, string> = {}): Promise<string> {
121122
let chunksWorkspace: string
122123
if (isPublic) {
123124
chunksWorkspace = `${getBaseUrl()}/public.php/dav/uploads/${getSharingToken()}`
@@ -128,7 +129,10 @@ export const initChunkWorkspace = async function(destinationFile: string | undef
128129
const hash = [...Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
129130
const tempWorkspace = `web-file-upload-${hash}`
130131
const url = `${chunksWorkspace}/${tempWorkspace}`
131-
const headers = destinationFile ? { Destination: destinationFile } : undefined
132+
const headers = customHeaders
133+
if (destinationFile) {
134+
headers.Destination = destinationFile
135+
}
132136

133137
await axios.request({
134138
method: 'MKCOL',

0 commit comments

Comments
 (0)