Currently the Strapi middleware in charge of parsing request needs to be configured to support bigger file sizes if you need to upload file with a size greater than 200MB.
The library we use is [`koa-body`](https://github.com/dlau/koa-body), and itself uses the [`node-formidable`](https://github.com/felixge/node-formidable) library to process files.
You can pass configuration to the middleware directly by setting it in the `parser` middleware configuration:
Your entry data has to be contained in a `data` key. You have to `JSON.stringify` your data object.
And for your files, they have to be prefixed by `files`.
Example here with cover attribute `files.cover`.
::: tip
If you want to upload files for a component, you will have to specify the index of the item you want to add the file to.
Example `files.my_component_name[the_index].attribute_name`
:::
::: warning
You have to send FormData in your request body
:::
## Models definition
Adding a file attribute to a model (or the model of another plugin) is like adding a new association.
In the first example below, you will be able to upload and attach one file to the avatar attribute.
**Path —** `User.settings.json`.
```json
{
"connection": "default",
"attributes": {
"pseudo": {
"type": "string",
"required": true
},
"email": {
"type": "email",
"required": true,
"unique": true
},
"avatar": {
"model": "file",
"via": "related",
"plugin": "upload"
}
}
}
```
In our second example, you can upload and attach multiple pictures to the restaurant.
**Path —** `Restaurant.settings.json`.
```json
{
"connection": "default",
"attributes": {
"name": {
"type": "string",
"required": true
},
"convers": {
"collection": "file",
"via": "related",
"plugin": "upload"
}
}
}
```
## Using a provider
By default Strapi provides a provider that uploads files to a local directory. You might want to upload your files to another provider like AWS S3.
You can check all the available providers developed by the community on npmjs.org - [Providers list](https://www.npmjs.com/search?q=strapi-provider-upload-)
If your package name is [scoped](https://docs.npmjs.com/about-scopes) (for example `@username/strapi-provider-upload-aws2`) you need to take an extra step by aliasing it in `package.json`. Go to the `dependencies` section and change the provider line to look like this:
When configuring your upload provider you might want to change the configuration based on the `NODE_ENV` environment variable or use environment specific credentials.
You can set a specific configuration in the `./config/env/{env}/plugins.js` configuration file and it will be used to overwrite the one in the default configuration.
## Create providers
You can create a Node.js module to implement a custom provider. Read the official documentation [here](https://docs.npmjs.com/creating-node-js-modules).
To work with strapi, your provider name must match the pattern `strapi-provider-upload-{provider-name}`.
Your provider need to export the following interface:
```js
module.exports = {
init(providerOptions) {
// init your provider if necessary
return {
upload(file) {
// upload the file in the provider
},
delete(file) {
// delete the file in the provider
},
};
},
};
```
You can then publish it to make it available to the community.
### Create a local provider
If you want to create your own provider without publishing it on **npm** you can follow these steps:
- Create a `./providers/strapi-provider-upload-{provider-name}` folder in your root application folder.
- Create your provider as explained in the [documentation](#create-providers) above.
- Then update your `package.json` to link your `strapi-provider-upload-{provider-name}` dependency to point to the [local path](https://docs.npmjs.com/files/package.json#local-paths) of your provider.