mirror of
https://github.com/strapi/strapi.git
synced 2025-12-28 23:57:32 +00:00
Upload: Apply fallback mime-type if none is set
This commit is contained in:
parent
88eadfcdfa
commit
be8b8a241d
@ -33,6 +33,7 @@
|
||||
"koa-range": "0.3.0",
|
||||
"koa-static": "5.0.0",
|
||||
"lodash": "4.17.21",
|
||||
"mime-types": "2.1.35",
|
||||
"react": "^17.0.2",
|
||||
"react-copy-to-clipboard": "^5.0.3",
|
||||
"react-dom": "^17.0.2",
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const mime = require('mime-types');
|
||||
const fse = require('fs-extra');
|
||||
const { getStreamSize } = require('./utils/file');
|
||||
|
||||
@ -48,7 +49,7 @@ module.exports = ({ strapi }) => {
|
||||
const currentFile = uploadService.formatFileInfo(
|
||||
{
|
||||
filename,
|
||||
type: mimetype,
|
||||
type: mimetype || mime.lookup(filename),
|
||||
size: await getStreamSize(createReadStream()),
|
||||
},
|
||||
extraInfo || {},
|
||||
@ -143,16 +144,16 @@ module.exports = ({ strapi }) => {
|
||||
const { files: uploads, ...metas } = args;
|
||||
|
||||
const files = await Promise.all(
|
||||
uploads.map(upload => formatFile(upload, {}, { ...metas, tmpWorkingDirectory }))
|
||||
uploads.map((upload) => formatFile(upload, {}, { ...metas, tmpWorkingDirectory }))
|
||||
);
|
||||
|
||||
const uploadService = getUploadService('upload');
|
||||
|
||||
const uploadedFiles = await Promise.all(
|
||||
files.map(file => uploadService.uploadFileAndPersist(file, {}))
|
||||
files.map((file) => uploadService.uploadFileAndPersist(file, {}))
|
||||
);
|
||||
|
||||
sanitizedEntities = uploadedFiles.map(file =>
|
||||
sanitizedEntities = uploadedFiles.map((file) =>
|
||||
toEntityResponse(file, { args, resourceUID: fileTypeName })
|
||||
);
|
||||
} finally {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user