Uploading file without multipart/form-data (server to server)

你离开我真会死。 提交于 2019-12-02 04:10:56

问题


From this answer https://stackoverflow.com/a/1695287/256400 , I get the feeling that multipart/form-data is needed to upload file from browser to server. But if my use case is to upload file from server to server shouldn't it work if I put the Content-Type as application/octet-stream or even specific types like image/png

I was experimenting with this on a node.js server and used fs.readFile to get the file content and used a REST library to do HTTP POST. But I am a bit confused on the encoding to be used when reading the file. Be default fs.readFile returns Buffer object. I was tempted to use binary But documentation here says it's binary is deprecated in favor of Buffer Objects. What would be the correct approach here to read the content of a file and upload? Can this be done without multipart/form-data


回答1:


Answering this since I found what I was looking for.

@npcode is correct. I didn't need to specify any encoding and I was able to work directly with Buffer object and I got it working.

I am now using request npm module which takes Buffer objects in body. My confusion arised from the rest client I was using initially which was mojito platforms rest client



来源:https://stackoverflow.com/questions/21413709/uploading-file-without-multipart-form-data-server-to-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!