Skip to main content
Skip to main content

Uploads

Mutations listed here are used to send requests to the Admin Upload API Routes.

All hooks listed 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.

Mutations

useAdminUploadFile

This hook uploads a file to a public bucket or storage. The file upload is handled by the file service installed on the Medusa backend.

Example

import React from "react"
import { useAdminUploadFile } from "medusa-react"

const UploadFile = () => {
const uploadFile = useAdminUploadFile()
// ...

const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}

// ...
}

export default UploadFile

Mutation Function Parameters

AdminCreateUploadPayloadAdminCreateUploadPayloadRequired

Mutation Function Returned Data

AdminUploadsResAdminUploadsResRequired
The list of uploaded files.

useAdminUploadProtectedFile

This hook uploads 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 React from "react"
import { useAdminUploadProtectedFile } from "medusa-react"

const UploadFile = () => {
const uploadFile = useAdminUploadProtectedFile()
// ...

const handleFileUpload = (file: File) => {
uploadFile.mutate(file, {
onSuccess: ({ uploads }) => {
console.log(uploads[0].key)
}
})
}

// ...
}

export default UploadFile

Mutation Function Parameters

AdminCreateUploadPayloadAdminCreateUploadPayloadRequired

Mutation Function Returned Data

AdminUploadsResAdminUploadsResRequired
The list of uploaded files.

useAdminCreatePresignedDownloadUrl

This hook creates 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 React from "react"
import { useAdminCreatePresignedDownloadUrl } from "medusa-react"

const Image = () => {
const createPresignedUrl = useAdminCreatePresignedDownloadUrl()
// ...

const handlePresignedUrl = (fileKey: string) => {
createPresignedUrl.mutate({
file_key: fileKey
}, {
onSuccess: ({ download_url }) => {
console.log(download_url)
}
})
}

// ...
}

export default Image

Mutation Function Parameters

AdminPostUploadsDownloadUrlReqAdminPostUploadsDownloadUrlReqRequired
The details of the file to retrieve its download URL.

Mutation Function Returned Data

AdminUploadsDownloadUrlResAdminUploadsDownloadUrlResRequired
The download URL details.

useAdminDeleteFile

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

Example

import React from "react"
import { useAdminDeleteFile } from "medusa-react"

const Image = () => {
const deleteFile = useAdminDeleteFile()
// ...

const handleDeleteFile = (fileKey: string) => {
deleteFile.mutate({
file_key: fileKey
}, {
onSuccess: ({ id, object, deleted }) => {
console.log(id)
}
})
}

// ...
}

export default Image

Mutation Function Parameters

AdminDeleteUploadsReqAdminDeleteUploadsReqRequired
The details of the file to delete.

Mutation Function Returned Data

DeleteResponseDeleteResponseRequired
The response returned for a DELETE request.
Was this section helpful?