upload - JS SDK Admin Reference

This documentation provides a reference to the sdk.admin.upload set of methods used to send requests to Medusa's Admin API routes.

create#

This method creates a new upload. It sends a request to the Upload Files API route.

Example#

Code
1sdk.admin.upload.create(2  {3    files: [4       // file uploaded as a base64 string5      {6        name: "test.txt",7        content: "test", // Should be the base64 content of the file8      },9      // file uploaded as a File object10      new File(["test"], "test.txt", { type: "text/plain" })11    ],12  }13)14.then(({ files }) => {15  console.log(files)16})

Parameters#

The details of the files to upload.
querySelectParamsOptional
Configure the fields and relations to retrieve in the uploaded files.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminFileListResponse>
The upload files' details.

retrieve#

This method retrieves a file's details by its ID. It sends a request to the Get File API route.

Example#

Code
1sdk.admin.upload.retrieve("test.txt")2.then(({ file }) => {3  console.log(file)4})

Parameters#

idstring
The ID of the file to retrieve.
querySelectParamsOptional
Query parameters to pass in the request.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminFileResponse>
The file's details.

delete#

This method deletes a file by its ID from the configured File Module Provider. It sends a request to the Delete File API route.

Example#

Code
1sdk.admin.upload.delete("test.txt")2.then(({ deleted }) => {3  console.log(deleted)4})

Parameters#

idstring
The ID of the file to delete.
headersClientHeadersOptional
Headers to pass in the request.

Returns#

PromisePromise<AdminFileDeleteResponse>
The deletion's details.
Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break