Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions __tests__/utils/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('Initialize chunks upload temporary workspace', () => {
retries: 5,
retryDelay: expect.any(Function),
},
headers: {},
})
})

Expand Down
2 changes: 1 addition & 1 deletion lib/uploader/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export class Uploader {
logger.debug('Initializing chunked upload', { file, upload })

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

// Generate chunks array
Expand Down
8 changes: 6 additions & 2 deletions lib/utils/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ export const getChunk = function(file: File, start: number, length: number): Pro
* @param destinationFile The file name after finishing the chunked upload
* @param retries number of retries
* @param isPublic whether this upload is in a public share or not
* @param customHeaders Custom HTTP headers used when creating the workspace (e.g. X-NC-Nickname for file drops)
*/
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false): Promise<string> {
export const initChunkWorkspace = async function(destinationFile: string | undefined = undefined, retries: number = 5, isPublic: boolean = false, customHeaders: Record<string, string> = {}): Promise<string> {
let chunksWorkspace: string
if (isPublic) {
chunksWorkspace = `${getBaseUrl()}/public.php/dav/uploads/${getSharingToken()}`
Expand All @@ -128,7 +129,10 @@ export const initChunkWorkspace = async function(destinationFile: string | undef
const hash = [...Array(16)].map(() => Math.floor(Math.random() * 16).toString(16)).join('')
const tempWorkspace = `web-file-upload-${hash}`
const url = `${chunksWorkspace}/${tempWorkspace}`
const headers = destinationFile ? { Destination: destinationFile } : undefined
const headers = customHeaders
if (destinationFile) {
headers.Destination = destinationFile
}

await axios.request({
method: 'MKCOL',
Expand Down
Loading