Should I upload images (multipart/formdata) to spaces via client or server side?

Is it considered safer by the digital ocean team to write the upload image code from server side? or is it indifferent and it is fine to write it from the client side? I have written the code already and it is working. Right now the code is in the server but just wondering if I can write it directly from the client to jump the maybe unecessary step of sending the image to my server

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 8, 2023

Hi there,

Totally with Zachary on this. I agree that offloading uploads directly from the client can significantly reduce backend load and save costs on memory and bandwidth. It also simplifies the process from a developer’s standpoint.

However, it’s important to weigh the pros and cons. While client-side uploads can be efficient and suitable for many use cases, server-side uploads offer several benefits.

For example, direct client-side uploads may expose additional security vulnerabilities, even with pre-signed URLs or temporary tokens. Using a server offers an extra layer of protection, enabling additional authentication, content validation, and possibly malware scans to ensure that uploads meet specific requirements.

As you mentioned, client-side uploads are straightforward. But routing uploads through the server provides better control over the entire process. For example, you can perform image transformations, add watermarks, save specific metadata, or ensure consistent error handling and logging. The server-side process offers a level of customization and control that direct client-side uploads might not easily accommodate.

Basically, the best approach will depend on the specific needs of your application.

I can’t speak for the Digital Ocean team specifically, but I’ve built several applications utilizing uploads.

I wouldn’t consider it inherently unsafe to do it from the client. That’s ideal in a lot of scenarios as to avoid load on your backend, reducing memory and bandwidth costs as well. The cognitive load of not having to worry about the binaries in transit (through your backend) is also a great benefit for you the developer.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel