From b8f6e96cdf40321e6c2e8a5f78d2400dd05d2ae9 Mon Sep 17 00:00:00 2001 From: Stuart Rowlands Date: Thu, 28 Nov 2024 14:31:51 +1000 Subject: [PATCH] Fixed file upload --- package.json | 2 +- src/client.ts | 16 ++++++++++++---- src/types.ts | 2 +- tests/client.test.ts | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 80b2507..356fad9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@quantcdn/quant-client", - "version": "2.0.2", + "version": "2.0.3", "description": "Client library for API connectivity", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/client.ts b/src/client.ts index f42a5fd..c60ba54 100644 --- a/src/client.ts +++ b/src/client.ts @@ -187,16 +187,24 @@ export class QuantClient { */ file: async (payload: types.FilePayload): Promise => { const headers = { - 'Content-Type': 'multipart/form-data', - 'Quant-File-Url': payload.location + 'Quant-File-Url': payload.url } - const formData = { data: payload.data } if (typeof payload.skipPurge !== 'undefined') { headers['Quant-Skip-Purge'] = 'true' } - return await this._project.post('file', {}, headers, formData) + const formData = { + file: { + value: payload.data, + options: { + filename: 'file', + contentType: 'application/octet-stream' + } + } + } + + return await this._project.post('file', undefined, headers, formData) }, /** diff --git a/src/types.ts b/src/types.ts index 82fe5e9..f851aa0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,7 +23,7 @@ export interface MarkupPayload { export interface FilePayload { data: Buffer - location: string + url: string skipPurge?: boolean } diff --git a/tests/client.test.ts b/tests/client.test.ts index eb35201..e47aa63 100644 --- a/tests/client.test.ts +++ b/tests/client.test.ts @@ -152,7 +152,7 @@ describe("Testing QuantClient", () => { }) test('file', () => { const payload:types.FilePayload = { - location: "/test/image.jpg", + url: "/test/image.jpg", data: Buffer.from('image') } })