我试图使用Sync-request将zip文件发送到端点,请求被命中服务器,但仍然从sync-request中获取错误
Error: unexpected end of file
var request = require('sync-request');
var fs = require('fs');
uploadData = fs.readFileSync("filepath/file.gz");
var url = "some endpoint url";
let res = request('PUT', url, {
headers: {
Authorization: authenticationToken,
},
Body: uploadData
})
答案 0 :(得分:0)
尝试使用此formData方法。最新版本可让您上传文件。但是,它不允许您流式传输文件上传。
const {FormData} = require('sync-request');
const fd = new FormData();
fd.append('file', fs.readFileSync(file_path), file_path);
request('PUT', url, {form: fd});
Ref:https://github.com/ForbesLindesay/sync-request/issues/63