Skip to content

Commit

Permalink
fix: multipart with remote storage
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Oct 13, 2024
1 parent d05aa74 commit fbca82e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
})
11 changes: 5 additions & 6 deletions src/runtime/blob/server/utils/blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,17 +396,17 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
return
},
async createMultipartUpload(pathname: string, options: BlobMultipartOptions = {}) {
return await blobAPI<BlobMultipartUpload>(`/multipart/${decodeURI(pathname)}`, {
return await blobAPI<BlobMultipartUpload>(`/multipart/create/${decodeURI(pathname)}`, {
method: 'POST',
body: options
query: options
})
},
resumeMultipartUpload(pathname: string, uploadId: string): BlobMultipartUpload {
return {
pathname,
uploadId,
async uploadPart(partNumber: number, body: string | ReadableStream<any> | ArrayBuffer | ArrayBufferView | Blob): Promise<BlobUploadedPart> {
return await blobAPI<BlobUploadedPart>(`/multipart/${decodeURI(pathname)}`, {
return await blobAPI<BlobUploadedPart>(`/multipart/upload/${decodeURI(pathname)}`, {
method: 'PUT',
query: {
uploadId,
Expand All @@ -416,18 +416,17 @@ export function proxyHubBlob(projectUrl: string, secretKey?: string): HubBlob {
})
},
async abort(): Promise<void> {
await blobAPI(`/multipart/${decodeURI(pathname)}`, {
await blobAPI(`/multipart/abort/${decodeURI(pathname)}`, {
method: 'DELETE',
query: {
uploadId
}
})
},
async complete(parts: BlobUploadedPart[]): Promise<BlobObject> {
return await blobAPI<BlobObject>('/multipart/complete', {
return await blobAPI<BlobObject>(`/multipart/complete/${decodeURI(pathname)}`, {
method: 'POST',
query: {
pathname,
uploadId
},
body: {
Expand Down

0 comments on commit fbca82e

Please sign in to comment.