@strapi/provider-upload-local 4.0.0-next.7 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +40 -19
  2. package/lib/index.js +5 -9
  3. package/package.json +18 -21
package/README.md CHANGED
@@ -1,30 +1,51 @@
1
- # strapi-provider-upload-local
1
+ # @strapi/provider-upload-local
2
2
 
3
- ## Configurations
3
+ ## Resources
4
4
 
5
- This provider has only one parameter: `sizeLimit`.
5
+ - [LICENSE](LICENSE)
6
+
7
+ ## Links
8
+
9
+ - [Strapi website](https://strapi.io/)
10
+ - [Strapi documentation](https://docs.strapi.io)
11
+ - [Strapi community on Discord](https://discord.strapi.io)
12
+ - [Strapi news on Twitter](https://twitter.com/strapijs)
6
13
 
7
- **Example**
14
+ ## Installation
8
15
 
9
- `./extensions/upload/config/settings.json`
16
+ ```bash
17
+ # using yarn
18
+ yarn add @strapi/provider-upload-local
10
19
 
11
- ```json
12
- {
13
- "provider": "local",
14
- "providerOptions": {
15
- "sizeLimit": 100000
16
- }
17
- }
20
+ # using npm
21
+ npm install @strapi/provider-upload-local --save
18
22
  ```
19
23
 
20
- The `sizeLimit` parameter must be a number. Be aware that the unit is in bytes, and the default is 1000000. When setting this value high, you should make sure to also configure the body parser middleware `maxFileSize` so the file can be sent and processed. Read more [here](https://strapi.io/documentation/developer-docs/latest/development/plugins/upload.html#configuration)
24
+ ## Configurations
21
25
 
22
- ## Resources
26
+ This provider has only one parameter: `sizeLimit`.
27
+
28
+ ### Provider Configuration
29
+
30
+ `./config/plugins.js`
31
+
32
+ ```js
33
+ module.exports = ({ env }) => ({
34
+ // ...
35
+ upload: {
36
+ config: {
37
+ provider: 'local',
38
+ providerOptions: {
39
+ sizeLimit: 100000,
40
+ },
41
+ },
42
+ },
43
+ // ...
44
+ });
45
+ ```
23
46
 
24
- - [License](LICENSE)
47
+ The `sizeLimit` parameter must be a number. Be aware that the unit is in bytes, and the default is 1000000. When setting this value high, you should make sure to also configure the body parser middleware `maxFileSize` so the file can be sent and processed. Read more [here](https://docs.strapi.io/developer-docs/latest/plugins/upload.html#configuration)
25
48
 
26
- ## Links
49
+ ### Security Middleware Configuration
27
50
 
28
- - [Strapi website](https://strapi.io/)
29
- - [Strapi community on Slack](https://slack.strapi.io)
30
- - [Strapi news on Twitter](https://twitter.com/strapijs)
51
+ Special configuration of the Strapi Security Middleware is not required on this provider since the default configuration allows loading images and media from `"'self'"`.
package/lib/index.js CHANGED
@@ -7,21 +7,17 @@
7
7
  // Public node modules.
8
8
  const fs = require('fs');
9
9
  const path = require('path');
10
- const { errors } = require('@strapi/plugin-upload');
10
+ const { PayloadTooLargeError } = require('@strapi/utils').errors;
11
11
 
12
12
  module.exports = {
13
13
  init({ sizeLimit = 1000000 } = {}) {
14
14
  const verifySize = file => {
15
15
  if (file.size > sizeLimit) {
16
- throw errors.entityTooLarge();
16
+ throw new PayloadTooLargeError();
17
17
  }
18
18
  };
19
- const configPublicPath = strapi.config.get(
20
- 'middleware.settings.public.path',
21
- strapi.config.paths.static
22
- );
23
19
 
24
- const uploadDir = path.resolve(strapi.dir, configPublicPath);
20
+ const publicDir = strapi.dirs.public;
25
21
 
26
22
  return {
27
23
  upload(file) {
@@ -30,7 +26,7 @@ module.exports = {
30
26
  return new Promise((resolve, reject) => {
31
27
  // write file in public/assets folder
32
28
  fs.writeFile(
33
- path.join(uploadDir, `/uploads/${file.hash}${file.ext}`),
29
+ path.join(publicDir, `/uploads/${file.hash}${file.ext}`),
34
30
  file.buffer,
35
31
  err => {
36
32
  if (err) {
@@ -46,7 +42,7 @@ module.exports = {
46
42
  },
47
43
  delete(file) {
48
44
  return new Promise((resolve, reject) => {
49
- const filePath = path.join(uploadDir, `/uploads/${file.hash}${file.ext}`);
45
+ const filePath = path.join(publicDir, `/uploads/${file.hash}${file.ext}`);
50
46
 
51
47
  if (!fs.existsSync(filePath)) {
52
48
  return resolve("File doesn't exist");
package/package.json CHANGED
@@ -1,48 +1,45 @@
1
1
  {
2
2
  "name": "@strapi/provider-upload-local",
3
- "version": "4.0.0-next.7",
3
+ "version": "4.0.1",
4
4
  "description": "Local provider for strapi upload",
5
- "homepage": "https://strapi.io",
6
5
  "keywords": [
7
6
  "upload",
8
7
  "strapi"
9
8
  ],
10
- "directories": {
11
- "lib": "./lib"
9
+ "homepage": "https://strapi.io",
10
+ "bugs": {
11
+ "url": "https://github.com/strapi/strapi/issues"
12
12
  },
13
- "main": "./lib",
14
- "strapi": {
15
- "isProvider": true
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git://github.com/strapi/strapi.git"
16
16
  },
17
+ "license": "SEE LICENSE IN LICENSE",
17
18
  "author": {
19
+ "name": "Strapi Solutions SAS",
18
20
  "email": "hi@strapi.io",
19
- "name": "Strapi team",
20
21
  "url": "https://strapi.io"
21
22
  },
22
23
  "maintainers": [
23
24
  {
24
- "name": "Strapi team",
25
+ "name": "Strapi Solutions SAS",
25
26
  "email": "hi@strapi.io",
26
27
  "url": "https://strapi.io"
27
28
  }
28
29
  ],
29
- "repository": {
30
- "type": "git",
31
- "url": "git://github.com/strapi/strapi.git"
30
+ "main": "./lib",
31
+ "directories": {
32
+ "lib": "./lib"
32
33
  },
33
- "peerDependencies": {
34
- "@strapi/plugin-upload": "^4.0.0"
34
+ "scripts": {
35
+ "test": "echo \"no tests yet\""
35
36
  },
36
- "bugs": {
37
- "url": "https://github.com/strapi/strapi/issues"
37
+ "dependencies": {
38
+ "@strapi/utils": "4.0.1"
38
39
  },
39
40
  "engines": {
40
41
  "node": ">=12.x.x <=16.x.x",
41
42
  "npm": ">=6.0.0"
42
43
  },
43
- "license": "SEE LICENSE IN LICENSE",
44
- "scripts": {
45
- "test": "echo \"no tests yet\""
46
- },
47
- "gitHead": "522d6afd54b68ed3376dd0c807fab6c1315f1931"
44
+ "gitHead": "e2cd01e8c6cbfeba15ad7787e38b6eebcbb92221"
48
45
  }