242Studios's avatar

Multiple Image Upload

I have a Vue app that uses a laravel rest api. I have a form field in the admin area for uploading product photos. It's a single upload field that allows multiple uploads. Right now I'm hitting an upload endpoint individually for each photo. So if there are six product photos, I make six separate requests to the same endpoint to upload those photos.

What I'm wondering is if it's better to just make one request for all of the photos instead. Yes, it's less requests but then it takes much longer to come back with a response. I would love to hear your thoughts.

-=Chris

0 likes
3 replies
242Studios's avatar

Thanks for that but I actually already have the code/logic sorted out. I'm just wondering if it's better to use the endpoint to upload one image at a time by sending requests for each image or if whether I should go the route of using a single request to send all the images to the endpoint.

I personally prefer to do them one at a time because the responses come back quicker for each individual image but in the back of my mind I'm thinking technically it's better to limit the requests sent.

jlrdw's avatar

Most would do several and loop over the request to get the images. I like limiting the number of images myself.

Say I allow up to 6. And only 2 are uploaded. Then I'd store the names for the 2, and just store null for others. But that's just the way I do it.

But a gallery you can't, one user may have 2, another 15.

For professional image handling, I'd use a good package that helps in the uploading and the displaying later of the images.

A good package will help with optimizing and proper rotation of the image.

A site I did had no such problem, it was in-house and adobe photoshop was used to get the images web ready. It was a Humane Society.

But letting trusting users to properly upload images, yikes.

Any developer should know the rule:

Never trust user input.

Please or to participate in this conversation.