Skip to content

Commit

Permalink
Fixed file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
stooit committed Nov 28, 2024
1 parent a1c6fde commit b8f6e96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
16 changes: 12 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,24 @@ export class QuantClient {
*/
file: async (payload: types.FilePayload): Promise<any> => {
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)
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface MarkupPayload {

export interface FilePayload {
data: Buffer
location: string
url: string
skipPurge?: boolean
}

Expand Down
2 changes: 1 addition & 1 deletion tests/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})
Expand Down

0 comments on commit b8f6e96

Please sign in to comment.