@strapi/provider-upload-local 4.1.0 → 4.1.1-alpha.0
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.
- package/lib/index.js +20 -1
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// Public node modules.
|
|
8
|
+
const { pipeline } = require('stream');
|
|
8
9
|
const fs = require('fs');
|
|
9
10
|
const path = require('path');
|
|
10
11
|
const { PayloadTooLargeError } = require('@strapi/utils').errors;
|
|
@@ -20,11 +21,29 @@ module.exports = {
|
|
|
20
21
|
const publicDir = strapi.dirs.public;
|
|
21
22
|
|
|
22
23
|
return {
|
|
24
|
+
uploadStream(file) {
|
|
25
|
+
verifySize(file);
|
|
26
|
+
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
pipeline(
|
|
29
|
+
file.stream,
|
|
30
|
+
fs.createWriteStream(path.join(publicDir, `/uploads/${file.hash}${file.ext}`)),
|
|
31
|
+
err => {
|
|
32
|
+
if (err) {
|
|
33
|
+
return reject(err);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
file.url = `/uploads/${file.hash}${file.ext}`;
|
|
37
|
+
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
},
|
|
23
43
|
upload(file) {
|
|
24
44
|
verifySize(file);
|
|
25
45
|
|
|
26
46
|
return new Promise((resolve, reject) => {
|
|
27
|
-
// write file in public/assets folder
|
|
28
47
|
fs.writeFile(
|
|
29
48
|
path.join(publicDir, `/uploads/${file.hash}${file.ext}`),
|
|
30
49
|
file.buffer,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/provider-upload-local",
|
|
3
|
-
"version": "4.1.0",
|
|
3
|
+
"version": "4.1.1-alpha.0",
|
|
4
4
|
"description": "Local provider for strapi upload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"upload",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"test": "echo \"no tests yet\""
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@strapi/utils": "4.1.0"
|
|
38
|
+
"@strapi/utils": "4.1.1-alpha.0"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=12.22.0 <=16.x.x",
|
|
42
42
|
"npm": ">=6.0.0"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "bedb04a0cc23719e4eac43e6005fe0fa3d48a9a6"
|
|
45
45
|
}
|