DEV Community

Discussion on: The Better Way of Sending Data to the Backend

Collapse
 
zyabxwcd profile image
Akash

I think one use case could be when you want to your APIs to use JSON. Sending form data means your API is consuming formats other than JSON. Also sending data in a form has some limitations I guess. Its best for as the name suggest forms. What if sending media is involved in a process that doesn't included one. I faced a scenario, and that is when I leaned about base64. I cant exactly remember what factors were stopping me from using form but I wanted to send and receive image data and I could not use a form so I had to follow this approach. The good thing is that you don't have to manually convert the image to base64 inside the browser. There is a web API that exposes a property named dataUrl that already contains the base64 form of the uploaded file.