From fbca82eabb4f5e5493b9cd2e350183f3b4d3e0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Sun, 13 Oct 2024 12:27:30 +0200 Subject: [PATCH] fix: multipart with remote storage --- .../api/_hub/blob/multipart/[action]/[...pathname].ts | 11 +++++++++-- src/runtime/blob/server/utils/blob.ts | 11 +++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/runtime/blob/server/api/_hub/blob/multipart/[action]/[...pathname].ts b/src/runtime/blob/server/api/_hub/blob/multipart/[action]/[...pathname].ts index d3f6cc39..dfbf4197 100644 --- a/src/runtime/blob/server/api/_hub/blob/multipart/[action]/[...pathname].ts +++ b/src/runtime/blob/server/api/_hub/blob/multipart/[action]/[...pathname].ts @@ -7,8 +7,15 @@ export default eventHandler(async (event) => { await requireNuxtHubAuthorization(event) requireNuxtHubFeature('blob') - const query = getQuery(event) + const options = { ...getQuery(event) } + if (typeof options.customMetadata === 'string') { + try { + options.customMetadata = JSON.parse(options.customMetadata) + } catch (e) { + options.customMetadata = {} + } + } return await hubBlob().handleMultipartUpload(event, { - ...query + ...options }) }) diff --git a/src/runtime/blob/server/utils/blob.ts b/src/runtime/blob/server/utils/blob.ts index a781bd10..939ef495 100644 --- a/src/runtime/blob/server/utils/blob.ts +++ b/src/runtime/blob/server/utils/blob.ts @@ -396,9 +396,9 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob { return }, async createMultipartUpload(pathname: string, options: BlobMultipartOptions = {}) { - return await blobAPI(`/multipart/${decodeURI(pathname)}`, { + return await blobAPI(`/multipart/create/${decodeURI(pathname)}`, { method: 'POST', - body: options + query: options }) }, resumeMultipartUpload(pathname: string, uploadId: string): BlobMultipartUpload { @@ -406,7 +406,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob { pathname, uploadId, async uploadPart(partNumber: number, body: string | ReadableStream | ArrayBuffer | ArrayBufferView | Blob): Promise { - return await blobAPI(`/multipart/${decodeURI(pathname)}`, { + return await blobAPI(`/multipart/upload/${decodeURI(pathname)}`, { method: 'PUT', query: { uploadId, @@ -416,7 +416,7 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob { }) }, async abort(): Promise { - await blobAPI(`/multipart/${decodeURI(pathname)}`, { + await blobAPI(`/multipart/abort/${decodeURI(pathname)}`, { method: 'DELETE', query: { uploadId @@ -424,10 +424,9 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob { }) }, async complete(parts: BlobUploadedPart[]): Promise { - return await blobAPI('/multipart/complete', { + return await blobAPI(`/multipart/complete/${decodeURI(pathname)}`, { method: 'POST', query: { - pathname, uploadId }, body: {