#Uploading images to Object Storage (S3)

1 messages · Page 1 of 1 (latest)

patent anvil
#

When parsing multipart forms and creating a custom upload handler the Remix examples raise a question for me. Why are we uploading the file to object storage before validating the other form fields? This flow doesn't seem right. If we use the s3 example here: https://github.com/remix-run/remix/tree/main/examples/file-and-s3-upload, what if we tried validating the imgDesc field and it failed? We would have uploaded the image anyways. Image attached is the cloudinary example from the docs.

fresh iris
#

hmm, depends of course on how you (wanna) handle things though I think it's not that simple because what are you doing with the image in the mean time? it has to go somewhere and it's generally "better" to store it somewhere on disk and external object storages are a good fit for this. Otherwise you'd have to keep it in memory while validating the rest of the form or defer the image upload.
All depends on your use case, if files are always small and you can just reject big files than it might be fine to keep them in memory, which should work by just using the memory upload handler alone. though even with small sizes you might have to consider, that multiple requests upload a file which all have to be hold in memory until further processed. Alternatively there's couple of ways of deferring the file upload, so post, validate and process everything else first, then maybe using a multi-step form ask the user to choose and upload the file..