Add previewUrl field and impl in cloudinary

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-03-16 14:09:35 +01:00
parent 8bac1b1835
commit 3889fb87dc
3 changed files with 16 additions and 17 deletions

View File

@ -1,8 +1,5 @@
'use strict';
const fse = require('fs-extra');
const { join } = require('path');
/**
* An asynchronous bootstrap function that runs before
* your application gets started.
@ -11,17 +8,4 @@ const { join } = require('path');
* run jobs, or perform some special logic.
*/
module.exports = async () => {
await fse.ensureDir('./public/uploads/sub-folder');
// example of overriding the upload provider
strapi.plugins.upload.provider.extend({
async upload(file) {
const filePath = `/uploads/sub-folder/${file.hash}${file.ext}`;
// write file in public/assets folder
await fse.writeFile(join(strapi.config.public.path, filePath), file.buffer);
file.url = filePath;
},
});
};
module.exports = () => {};

View File

@ -57,6 +57,10 @@
"configurable": false,
"required": true
},
"previewUrl": {
"type": "string",
"configurable": false
},
"provider": {
"type": "string",
"configurable": false,

View File

@ -21,6 +21,17 @@ module.exports = {
if (err) {
return reject(err);
}
if (image.resource_type === 'video') {
file.previewUrl = cloudinary.url(`${image.public_id}.gif`, {
video_sampling: 6,
delay: 200,
width: 250,
crop: 'scale',
resource_type: 'video',
});
}
file.url = image.secure_url;
file.provider_metadata = {
public_id: image.public_id,