0

I am using Angular in the front and Nodejs + Express 4 at backend. When I'm trying to upload a file using simple html form, the request contains:

Content-Type: image/jpeg

whereas plugings like busboy, connect-busboy etc. require Content-Type to be multipart/form-data and hence there is nothing in req.files

What I'm missing here?

halfer
  • 19,824
  • 17
  • 99
  • 186
Ashutosh
  • 4,371
  • 10
  • 59
  • 105

1 Answers1

1

It might not relate to your question. However, let me leave some workaround I did when I had the same issue like you. I totally agree that it could be a bit tricky to send files over the wire from Angular to Express.

What I came up with was compiling files into base64 string. And decode them when the backend grabs the base64 string data. This way could easily avoid the issue you mentioned on your post.

Secondly, if your app is in microservice architecture, and if you are willing to do so, use Amazon S3 or Cloudinary to store your data. And you will just save the link url for the files in your database. By doing so, you can reduce significant amount of request to your backend, and you can deal with the data easily.

Hope these solutions work for you!

supergentle
  • 1,001
  • 1
  • 14
  • 33
  • Is it a good idea to send files as base64? Which is better in efficiency? Will be using S3 in future but not now, thanks – Ashutosh Nov 28 '17 at 07:47
  • @Ashutosh We gotta keep in mind that base64 will be always 33% larger than the original raw data file. If your file is expected to be big and you are so much care about reducing traffic data. I wouldn't recommend using base64. However, if you don't, base64 could be a workaround. – supergentle Nov 28 '17 at 07:51