feat: add presignedUrl method to upload sdk (#12569)

This commit is contained in:
Christian
2025-05-21 22:21:50 +02:00
committed by GitHub
parent c5a6573e26
commit ca9ffcc80b
+40 -8
View File
@@ -18,16 +18,16 @@ export class Upload {
* This method creates a new upload. It sends a request to the * This method creates a new upload. It sends a request to the
* [Upload Files](https://docs.medusajs.com/api/admin#uploads_postuploads) * [Upload Files](https://docs.medusajs.com/api/admin#uploads_postuploads)
* API route. * API route.
* *
* @param body - The details of the files to upload. * @param body - The details of the files to upload.
* @param query - Configure the fields and relations to retrieve in the uploaded files. * @param query - Configure the fields and relations to retrieve in the uploaded files.
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* @returns The upload files' details. * @returns The upload files' details.
* *
* @privateRemarks * @privateRemarks
* *
* Note: The creation/upload flow be made more advanced, with support for streaming and progress, but for now we keep it simple * Note: The creation/upload flow be made more advanced, with support for streaming and progress, but for now we keep it simple
* *
* @example * @example
* sdk.admin.upload.create( * sdk.admin.upload.create(
* { * {
@@ -89,12 +89,12 @@ export class Upload {
* This method retrieves a file's details by its ID. It sends a request to the * This method retrieves a file's details by its ID. It sends a request to the
* [Get File](https://docs.medusajs.com/api/admin#uploads_getuploadsid) * [Get File](https://docs.medusajs.com/api/admin#uploads_getuploadsid)
* API route. * API route.
* *
* @param id - The ID of the file to retrieve. * @param id - The ID of the file to retrieve.
* @param query - Query parameters to pass in the request. * @param query - Query parameters to pass in the request.
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* @returns The file's details. * @returns The file's details.
* *
* @example * @example
* sdk.admin.upload.retrieve("test.txt") * sdk.admin.upload.retrieve("test.txt")
* .then(({ file }) => { * .then(({ file }) => {
@@ -115,11 +115,11 @@ export class Upload {
* This method deletes a file by its ID from the configured File Module Provider. It sends a request to the * This method deletes a file by its ID from the configured File Module Provider. It sends a request to the
* [Delete File](https://docs.medusajs.com/api/admin#uploads_deleteuploadsid) * [Delete File](https://docs.medusajs.com/api/admin#uploads_deleteuploadsid)
* API route. * API route.
* *
* @param id - The ID of the file to delete. * @param id - The ID of the file to delete.
* @param headers - Headers to pass in the request. * @param headers - Headers to pass in the request.
* @returns The deletion's details. * @returns The deletion's details.
* *
* @example * @example
* sdk.admin.upload.delete("test.txt") * sdk.admin.upload.delete("test.txt")
* .then(({ deleted }) => { * .then(({ deleted }) => {
@@ -135,4 +135,36 @@ export class Upload {
} }
) )
} }
/**
* This method creates a presigned URL for a file upload. It sends a request to the
* `/admin/uploads/presigned-urls` API route.
*
* @param body - The details of the file to upload.
* @param query - Query parameters to pass in the request.
* @param headers - Headers to pass in the request.
* @returns The presigned URL for the file upload.
*
* @example
* sdk.admin.upload.presignedUrl({
* name: "test.txt",
* size: 1000,
* type: "text/plain",
* }))
*/
async presignedUrl(
body: HttpTypes.AdminUploadPreSignedUrlRequest,
query?: SelectParams,
headers?: ClientHeaders
) {
return this.client.fetch<HttpTypes.AdminUploadPreSignedUrlResponse>(
`/admin/uploads/presigned-urls`,
{
method: "POST",
headers,
body,
query,
}
)
}
} }