mirror of
https://github.com/strapi/strapi.git
synced 2025-07-23 17:10:08 +00:00
19 lines
544 B
JavaScript
19 lines
544 B
JavaScript
![]() |
'use strict';
|
||
|
|
||
|
const { isFunction } = require('lodash/fp');
|
||
|
const { streamToBuffer } = require('../utils/file');
|
||
|
|
||
|
module.exports = ({ strapi }) => ({
|
||
|
async upload(file) {
|
||
|
if (isFunction(strapi.plugin('upload').provider.uploadStream)) {
|
||
|
file.stream = file.getStream();
|
||
|
await strapi.plugin('upload').provider.uploadStream(file);
|
||
|
delete file.stream;
|
||
|
} else {
|
||
|
file.buffer = await streamToBuffer(file.getStream());
|
||
|
await strapi.plugin('upload').provider.upload(file);
|
||
|
delete file.buffer;
|
||
|
}
|
||
|
},
|
||
|
});
|