added server side validation for both image upload forms
This commit is contained in:
parent
b73338a0f3
commit
c592853852
|
@ -16,6 +16,13 @@ export async function action({ request }) {
|
|||
directory: './public/uploads/',
|
||||
maxPartSize: 500000,
|
||||
file: ({ filename }) => filename,
|
||||
filter: data => {
|
||||
const fileTypes = ['jpeg', 'jpg', 'png', 'gif']
|
||||
// if sent file is not an image, don't handle it
|
||||
if (!fileTypes.includes(data.contentType.split('/')[1])) return false;
|
||||
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const errors = {};
|
||||
|
@ -25,7 +32,7 @@ export async function action({ request }) {
|
|||
multiPartformdata = await unstable_parseMultipartFormData(request, fileUploadHandler);
|
||||
imageName = multiPartformdata.get("image").name;
|
||||
} catch (err) {
|
||||
errors.image = "Image size too big";
|
||||
errors.image = "Image size too big or file sent is not an image";
|
||||
}
|
||||
|
||||
if (typeof title !== "string" || title.length > 50 || title.length < 3) {
|
||||
|
|
|
@ -17,6 +17,13 @@ export async function action({ request, params }) {
|
|||
directory: './public/uploads/',
|
||||
maxPartSize: 500000,
|
||||
file: ({ filename }) => filename,
|
||||
filter: data => {
|
||||
const fileTypes = ['jpeg', 'jpg', 'png', 'gif']
|
||||
// if sent file is not an image, don't handle it
|
||||
if (!fileTypes.includes(data.contentType.split('/')[1])) return false;
|
||||
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const errors = {};
|
||||
|
|
Loading…
Reference in New Issue