Skip to content

Commit

Permalink
style: 📝 Improve error message of file upload by adding an example (s…
Browse files Browse the repository at this point in the history
…trapi#7111)

Signed-off-by: Abdellah Alaoui <als.abdellah@gmail.com>
Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
  • Loading branch information
haikyuu authored and onepointconsulting committed Aug 13, 2020
1 parent 02727f9 commit 3fd3980
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/strapi-utils/lib/parse-multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ module.exports = ctx => {
try {
data = JSON.parse(body.data);
} catch (error) {
throw strapi.errors.badRequest(
`Invalid 'data' field. 'data' should be a valid JSON.`
);
throw strapi.errors.badRequest(`Invalid 'data' field. 'data' should be a valid JSON.`);
}

const filesToUpload = Object.keys(files).reduce((acc, key) => {
const fullPath = _.toPath(key);

if (fullPath.length <= 1 || fullPath[0] !== 'files') {
throw strapi.errors.badRequest(
`When using multipart/form-data you need to provide your files by prefixing them with the 'files'.`
`When using multipart/form-data you need to provide your files by prefixing them with the 'files'.
For example, when a media file is named "avatar", make sure the form key name is "files.avatar"`
);
}

Expand Down

0 comments on commit 3fd3980

Please sign in to comment.