data (server to server)
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
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
链接地址: http://www.djcxy.com/p/22216.html上一篇: 使用multipart / form的HMAC认证API调用
下一篇: 数据(服务器到服务器)