Skip to main content
Skip to main content

AdminUploadsResource

This class is used to send requests to Admin Upload API Routes. All its method are available in the JS Client under the medusa.admin.uploads property.

All methods in this class require authentication.

The methods in this class are used to upload any type of resources. For example, they can be used to upload CSV files that are used to import products into the store.

Related Guide: How to upload CSV file when importing a product.

Methods

create

Upload a file or multiple files to a public bucket or storage. The file upload is handled by the file service installed on the Medusa backend.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.uploads.create(file)
.then(({ uploads }) => {
console.log(uploads.length);
})

Parameters

fileAdminCreateUploadPayloadRequired
The file(s) to upload.

Returns

ResponsePromiseResponsePromise<AdminUploadsRes>Required
Resolves to the uploaded file details.

createProtected

Upload a file to an ACL or a non-public bucket. The file upload is handled by the file service installed on the Medusa backend.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.uploads.createProtected(file)
.then(({ uploads }) => {
console.log(uploads.length);
})

Parameters

fileAdminCreateUploadPayloadRequired
The file to upload.

Returns

ResponsePromiseResponsePromise<AdminUploadsRes>Required
Resolves to the uploaded file details.

delete

Delete an uploaded file from storage. The file is deleted using the installed file service on the Medusa backend.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.uploads.delete({
file_key
})
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters

payloadAdminDeleteUploadsReqRequired
The uploaded file to delete.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

getPresignedDownloadUrl

Create and retrieve a presigned or public download URL for a file. The URL creation is handled by the file service installed on the Medusa backend.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.uploads.getPresignedDownloadUrl({
file_key
})
.then(({ download_url }) => {
console.log(download_url);
})

Parameters

The uploaded file to get a presigned download URL for.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminUploadsDownloadUrlRes>Required
Resolves to the download URL details.

_createPayload

Parameters

fileAdminCreateUploadPayloadRequired

Returns

FormDataFormDataRequired
Was this section helpful?