---
displayed_sidebar: jsClientSidebar
slug: /references/js-client/AdminUploadsResource
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# AdminUploadsResource

This class is used to send requests to [Admin Upload API Routes](https://docs.medusajs.com/api/admin#uploads). All its method
are available in the JS Client under the `medusa.admin.uploads` property.

All methods in this class require [user authentication](AdminAuthResource.mdx#createsession).

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](https://docs.medusajs.com/modules/products/admin/import-products#1-upload-csv-file).

## Methods

### \_createPayload

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "file",
    "type": "[`AdminCreateUploadPayload`](../modules/internal.mdx#admincreateuploadpayload)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "FormData",
    "type": "`FormData`",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### create

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

#### Example

```ts
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

<ParameterTypes parameters={[
  {
    "name": "file",
    "type": "[`AdminCreateUploadPayload`](../modules/internal.mdx#admincreateuploadpayload)",
    "description": "The file to upload.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "[`ResponsePromise`](../modules/internal.mdx#responsepromise)<[`AdminUploadsRes`](../modules/internal.mdx#adminuploadsres)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the uploaded file details.",
    "expandable": false,
    "children": [
      {
        "name": "AdminUploadsRes",
        "type": "`object`",
        "description": "The list of uploaded files.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "uploads",
            "type": "[`FileServiceUploadResult`](../modules/internal.mdx#fileserviceuploadresult)[]",
            "description": "Uploaded files details.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": [
              {
                "name": "key",
                "type": "`string`",
                "description": "The key of the file that is identifiable by the file service. It can be used later to retrieve or manipulate the file.",
                "optional": false,
                "defaultValue": "",
                "expandable": false,
                "children": []
              },
              {
                "name": "url",
                "type": "`string`",
                "description": "The URL of the uploaded file.",
                "optional": false,
                "defaultValue": "",
                "expandable": false,
                "children": []
              }
            ]
          }
        ]
      }
    ]
  }
]} />

___

### 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

```ts
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

<ParameterTypes parameters={[
  {
    "name": "file",
    "type": "[`AdminCreateUploadPayload`](../modules/internal.mdx#admincreateuploadpayload)",
    "description": "The file to upload.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "[`ResponsePromise`](../modules/internal.mdx#responsepromise)<[`AdminUploadsRes`](../modules/internal.mdx#adminuploadsres)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the uploaded file details.",
    "expandable": false,
    "children": [
      {
        "name": "AdminUploadsRes",
        "type": "`object`",
        "description": "The list of uploaded files.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "uploads",
            "type": "[`FileServiceUploadResult`](../modules/internal.mdx#fileserviceuploadresult)[]",
            "description": "Uploaded files details.",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": [
              {
                "name": "key",
                "type": "`string`",
                "description": "The key of the file that is identifiable by the file service. It can be used later to retrieve or manipulate the file.",
                "optional": false,
                "defaultValue": "",
                "expandable": false,
                "children": []
              },
              {
                "name": "url",
                "type": "`string`",
                "description": "The URL of the uploaded file.",
                "optional": false,
                "defaultValue": "",
                "expandable": false,
                "children": []
              }
            ]
          }
        ]
      }
    ]
  }
]} />

___

### delete

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

#### Example

```ts
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

<ParameterTypes parameters={[
  {
    "name": "payload",
    "type": "[`AdminDeleteUploadsReq`](../internal/classes/internal.AdminDeleteUploadsReq.mdx)",
    "description": "The uploaded file to delete.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "file_key",
        "type": "`string`",
        "description": "key of the file to delete. This is obtained when you first uploaded the file, or by the file service if you used it directly.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "Record<`string`, `any`\\>",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "[`ResponsePromise`](../modules/internal.mdx#responsepromise)<[`DeleteResponse`](../internal/interfaces/internal.DeleteResponse.mdx)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the deletion operation's details.",
    "expandable": false,
    "children": [
      {
        "name": "deleted",
        "type": "`boolean`",
        "description": "Whether the item was deleted successfully.",
        "optional": false,
        "defaultValue": "true",
        "expandable": false,
        "children": []
      },
      {
        "name": "id",
        "type": "`string`",
        "description": "The ID of the deleted item.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      },
      {
        "name": "object",
        "type": "`string`",
        "description": "The type of the deleted item.",
        "optional": false,
        "defaultValue": "product-collection",
        "expandable": false,
        "children": []
      }
    ]
  }
]} />

___

### 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

```ts
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

<ParameterTypes parameters={[
  {
    "name": "payload",
    "type": "[`AdminPostUploadsDownloadUrlReq`](../internal/classes/internal.AdminPostUploadsDownloadUrlReq.mdx)",
    "description": "The uploaded file to get a presigned download URL for.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": [
      {
        "name": "file_key",
        "type": "`string`",
        "description": "key of the file to obtain the download link for. This is obtained when you first uploaded the file, or by the file service if you used it directly.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": []
      }
    ]
  },
  {
    "name": "customHeaders",
    "type": "Record<`string`, `any`\\>",
    "description": "Custom headers to attach to the request.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ResponsePromise",
    "type": "[`ResponsePromise`](../modules/internal.mdx#responsepromise)<[`AdminUploadsDownloadUrlRes`](../modules/internal.mdx#adminuploadsdownloadurlres)\\>",
    "optional": false,
    "defaultValue": "",
    "description": "Resolves to the download URL details.",
    "expandable": false,
    "children": [
      {
        "name": "AdminUploadsDownloadUrlRes",
        "type": "`object`",
        "description": "The download URL details.",
        "optional": false,
        "defaultValue": "",
        "expandable": false,
        "children": [
          {
            "name": "download_url",
            "type": "`string`",
            "description": "The Download URL of the file",
            "optional": false,
            "defaultValue": "",
            "expandable": false,
            "children": []
          }
        ]
      }
    ]
  }
]} />
