diff --git a/__tests__/utils/upload.spec.ts b/__tests__/utils/upload.spec.ts index 02299147..5ec362b1 100644 --- a/__tests__/utils/upload.spec.ts +++ b/__tests__/utils/upload.spec.ts @@ -117,6 +117,9 @@ describe('Upload data', () => { data: blob, signal, onUploadProgress, + headers: { + 'Content-Type': 'application/octet-stream', + }, }) }) test('Upload async data stream', async () => { @@ -139,6 +142,9 @@ describe('Upload data', () => { data: blob, signal, onUploadProgress, + headers: { + 'Content-Type': 'application/octet-stream', + }, }) }) @@ -161,6 +167,7 @@ describe('Upload data', () => { onUploadProgress, headers: { Destination: url, + 'Content-Type': 'application/octet-stream', }, }) }) diff --git a/lib/uploader.ts b/lib/uploader.ts index 9bdda4b7..f6bcc76a 100644 --- a/lib/uploader.ts +++ b/lib/uploader.ts @@ -215,6 +215,7 @@ export class Uploader { { 'X-OC-Mtime': file.lastModified / 1000, 'OC-Total-Length': file.size, + 'Content-Type': 'application/octet-stream', }, ) // Update upload progress on chunk completion @@ -284,6 +285,7 @@ export class Uploader { undefined, { 'X-OC-Mtime': file.lastModified / 1000, + 'Content-Type': file.type, }, ) diff --git a/lib/utils/upload.ts b/lib/utils/upload.ts index 5a9c133e..259f111f 100644 --- a/lib/utils/upload.ts +++ b/lib/utils/upload.ts @@ -11,21 +11,41 @@ type UploadData = Blob | (() => Promise) /** * Upload some data to a given path + * @param url the url to upload to + * @param uploadData the data to upload + * @param signal the abort signal + * @param onUploadProgress the progress callback + * @param destinationFile the final destination file (often used for chunked uploads) + * @param headers additional headers */ -export const uploadData = async function(url: string, uploadData: UploadData, signal: AbortSignal, onUploadProgress = () => {}, destinationFile: string | undefined = undefined, headers: any = undefined): Promise { +export const uploadData = async function( + url: string, + uploadData: UploadData, + signal: AbortSignal, + onUploadProgress = () => {}, + destinationFile: string | undefined = undefined, + headers: Record = {}, +): Promise { let data: Blob + // If the upload data is a blob, we can directly use it + // Otherwise, we need to wait for the promise to resolve if (uploadData instanceof Blob) { data = uploadData } else { data = await uploadData() } + // Helps the server to know what to do with the file afterwards (e.g. chunked upload) if (destinationFile) { - headers ??= {} headers.Destination = destinationFile } + // If no content type is set, we default to octet-stream + if (!headers['Content-Type']) { + headers['Content-Type'] = 'application/octet-stream' + } + return await axios.request({ method: 'PUT', url, diff --git a/package.json b/package.json index 87447a2b..ec6adbf8 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "cypress": "cypress run --component", "cypress:gui": "cypress open --component", "test": "vitest run", - "test:watch": "vitest run --watchAll --verbose true", + "test:watch": "vitest run --watch", "test:coverage": "vitest run --coverage", "l10n:extract": "node build/extract-l10n.js" },