Skip to content

Commit ca9ffcc

Browse files
feat: add presignedUrl method to upload sdk (medusajs#12569)
1 parent c5a6573 commit ca9ffcc

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

packages/core/js-sdk/src/admin/upload.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ export class Upload {
1818
* This method creates a new upload. It sends a request to the
1919
* [Upload Files](https://docs.medusajs.com/api/admin#uploads_postuploads)
2020
* API route.
21-
*
21+
*
2222
* @param body - The details of the files to upload.
2323
* @param query - Configure the fields and relations to retrieve in the uploaded files.
2424
* @param headers - Headers to pass in the request.
2525
* @returns The upload files' details.
26-
*
26+
*
2727
* @privateRemarks
28-
*
28+
*
2929
* Note: The creation/upload flow be made more advanced, with support for streaming and progress, but for now we keep it simple
30-
*
30+
*
3131
* @example
3232
* sdk.admin.upload.create(
3333
* {
@@ -89,12 +89,12 @@ export class Upload {
8989
* This method retrieves a file's details by its ID. It sends a request to the
9090
* [Get File](https://docs.medusajs.com/api/admin#uploads_getuploadsid)
9191
* API route.
92-
*
92+
*
9393
* @param id - The ID of the file to retrieve.
9494
* @param query - Query parameters to pass in the request.
9595
* @param headers - Headers to pass in the request.
9696
* @returns The file's details.
97-
*
97+
*
9898
* @example
9999
* sdk.admin.upload.retrieve("test.txt")
100100
* .then(({ file }) => {
@@ -115,11 +115,11 @@ export class Upload {
115115
* This method deletes a file by its ID from the configured File Module Provider. It sends a request to the
116116
* [Delete File](https://docs.medusajs.com/api/admin#uploads_deleteuploadsid)
117117
* API route.
118-
*
118+
*
119119
* @param id - The ID of the file to delete.
120120
* @param headers - Headers to pass in the request.
121121
* @returns The deletion's details.
122-
*
122+
*
123123
* @example
124124
* sdk.admin.upload.delete("test.txt")
125125
* .then(({ deleted }) => {
@@ -135,4 +135,36 @@ export class Upload {
135135
}
136136
)
137137
}
138+
139+
/**
140+
* This method creates a presigned URL for a file upload. It sends a request to the
141+
* `/admin/uploads/presigned-urls` API route.
142+
*
143+
* @param body - The details of the file to upload.
144+
* @param query - Query parameters to pass in the request.
145+
* @param headers - Headers to pass in the request.
146+
* @returns The presigned URL for the file upload.
147+
*
148+
* @example
149+
* sdk.admin.upload.presignedUrl({
150+
* name: "test.txt",
151+
* size: 1000,
152+
* type: "text/plain",
153+
* }))
154+
*/
155+
async presignedUrl(
156+
body: HttpTypes.AdminUploadPreSignedUrlRequest,
157+
query?: SelectParams,
158+
headers?: ClientHeaders
159+
) {
160+
return this.client.fetch<HttpTypes.AdminUploadPreSignedUrlResponse>(
161+
`/admin/uploads/presigned-urls`,
162+
{
163+
method: "POST",
164+
headers,
165+
body,
166+
query,
167+
}
168+
)
169+
}
138170
}

0 commit comments

Comments
 (0)