How to upload file to server in right way?

I have model User and I want to develop uploading avatar to server or to S3 bucket(but I think it’s dangerous) What is the best practice to upload files to server? I have two ideas. First to send file to server with jquery ajax. Second to encode file to base64 set it to model of user who changes avatar and save this model, in this case Ember will send PATCH request to my API.

Thank you

1 Like

how is your API done? does it expect the file data as base64 or does it have a resource for uploading (posting, putting) binary data? if you have the freedom to choose, I would go for an extra resource expecting binary data as a PUT request. It is however mostly a personal preference and also the fact that base64 if generally between 25 to 30% more data.

I’m dealing with this same issue right now.

I think the problem is that there isn’t really a “recommended” approach for binary file uploads to a JSON API.

See this json-api GitHub open issue comment for a great characterization of the dilemma.

1 Like