From d37dd640d3fa952f201487232d0d55cd08c2c56f Mon Sep 17 00:00:00 2001 From: Gabriel <83644514+gpene@users.noreply.github.com> Date: Mon, 27 Jun 2022 13:44:57 +0200 Subject: [PATCH 1/3] Update upload.md --- docs/developer-docs/latest/plugins/upload.md | 246 +++++-------------- 1 file changed, 55 insertions(+), 191 deletions(-) diff --git a/docs/developer-docs/latest/plugins/upload.md b/docs/developer-docs/latest/plugins/upload.md index 4ce38efb77..ab41a8a66d 100644 --- a/docs/developer-docs/latest/plugins/upload.md +++ b/docs/developer-docs/latest/plugins/upload.md @@ -6,10 +6,47 @@ canonicalUrl: https://docs.strapi.io/developer-docs/latest/plugins/upload.html # Upload -The `Upload` plugin is used to implement the Media Library available in the admin panel. With it you can upload any kind of file on your server or external providers such as **AWS S3**. +The `Upload` plugin is the backend powering the [Media Library](../../../user-docs/latest/media-library/introduction-to-media-library.md) plugin available by default in the Strapi admin panel. + +Using either the Media Library UI or the upload API directly, you can upload any kind of file for use in your Strapi application. + +By default Strapi provides a [provider](../development/using-providers.md) that uploads files to a local directory. Additional providers are available should you want to upload your files to another location. + +The providers maintained by Strapi include: + +- [Amazon S3](https://www.npmjs.com/package/@strapi/provider-upload-aws-s3) +- [Cloudinary](https://www.npmjs.com/package/@strapi/provider-upload-cloudinary) +- [Local](https://www.npmjs.com/package/@strapi/provider-upload-local) +- [Rackspace](https://www.npmjs.com/package/@strapi/provider-upload-rackspace) ## Configuration +This section details configuration options for the default upload provider. If using another provider (e.g. AWS S3 or Rackspace), see the available configuration parameters in that provider's documentation. + +### Local server + +By default Strapi accepts `localServer` configurations for locally uploaded files. These will be passed as the options for [koa-static](https://github.com/koajs/static). + +You can provide them by creating or editing the `./config/plugins.js` file. The example below sets the `max-age` header. + +```js +// path: ./config/plugins.js + +module.exports = ({ env })=>({ + upload: { + config: { + providerOptions: { + localServer: { + maxage: 300000 + }, + }, + }, + }, +}); +``` + +### Max file size + Currently the Strapi middleware in charge of parsing requests needs to be configured to support file sizes larger than the default of **200MB**. The library we use is [`koa-body`](https://github.com/dlau/koa-body), and it uses the [`node-formidable`](https://github.com/felixge/node-formidable) library to process files. @@ -36,7 +73,7 @@ module.exports = { }; ``` -### Responsive Images +### Responsive images When the `Enable responsive friendly upload` setting is enabled in the settings panel the plugin will generate the following responsive image sizes: | Name | Largest Dimension | @@ -105,11 +142,13 @@ module.exports = ({ env }) => ({ -## Upload files +## Examples -To upload files to your application. +### Upload files -### Parameters +Upload one or more files to your application. + +The following parameters are accepted: - `files`: The file(s) to upload. The value(s) can be a Buffer or Stream. @@ -166,11 +205,11 @@ const response = await fetch('http://localhost:1337/api/upload', { You have to send FormData in your request body. ::: -## Upload files related to an entry +### Upload entry files -To upload files that will be linked to a specific entry. +Upload one or more files that will be linked to a specific entry. -### Request parameters +The following parameters are accepted: - `files`: The file(s) to upload. The value(s) can be a Buffer or Stream. - `path` (optional): The folder where the file(s) will be uploaded to (only supported on strapi-provider-upload-aws-s3). @@ -179,9 +218,7 @@ To upload files that will be linked to a specific entry. - `source` (optional): The name of the plugin where the model is located. - `field`: The field of the entry which the file(s) will be precisely linked to. -### Examples - -The `Restaurant` model attributes: +For example, given the `Restaurant` model attributes: ```json // path: ./src/api/restaurant/content-types/restaurant/schema.json @@ -201,7 +238,7 @@ The `Restaurant` model attributes: } ``` -Code +The corresponding code would be: ```html