implement uploadStream wrapping for actionOptions

This commit is contained in:
Pierre Noël 2022-03-14 17:14:12 +01:00
parent 3bf25de33e
commit 091a3d3d85
2 changed files with 8 additions and 1 deletions

View File

@ -51,6 +51,10 @@ const createProvider = config => {
return Object.assign(Object.create(baseProvider), { return Object.assign(Object.create(baseProvider), {
...providerInstance, ...providerInstance,
original: providerInstance,
uploadStream(file, options = actionOptions.upload) {
return providerInstance.uploadStream(file, options);
},
upload(file, options = actionOptions.upload) { upload(file, options = actionOptions.upload) {
return providerInstance.upload(file, options); return providerInstance.upload(file, options);
}, },
@ -64,6 +68,9 @@ const baseProvider = {
extend(obj) { extend(obj) {
Object.assign(this, obj); Object.assign(this, obj);
}, },
uploadStream() {
throw new Error('Provider uploadStream method is not implemented');
},
upload() { upload() {
throw new Error('Provider upload method is not implemented'); throw new Error('Provider upload method is not implemented');
}, },

View File

@ -5,7 +5,7 @@ const { streamToBuffer } = require('../utils/file');
module.exports = ({ strapi }) => ({ module.exports = ({ strapi }) => ({
async upload(file) { async upload(file) {
if (isFunction(strapi.plugin('upload').provider.uploadStream)) { if (isFunction(strapi.plugin('upload').provider.original.uploadStream)) {
file.stream = file.getStream(); file.stream = file.getStream();
await strapi.plugin('upload').provider.uploadStream(file); await strapi.plugin('upload').provider.uploadStream(file);
delete file.stream; delete file.stream;