根据本文档,我正在使用节点请求并尝试将文件发送到 IBM 的 HDFS 。
传递此 JSON 对象以请求成功上传:
var options = {
method: 'put',
body: 'foo',
headers: {
'Content-Type': 'application/octet-stream',
'Transfer-Encoding': 'chunked'
}
};
并且运行这个 CURL 命令也成功上传了一个文件:
curl -v -X PUT -L -b cookie.jar "https://host:port/webhdfs/v1/tmp/myLargeFile.zip?op=CREATE&data=true" --header "Content-Type:application/octet-stream" --header "Transfer-Encoding:chunked" -T "file.txt"
但是,尝试像这样指定文件流:
var options = {
method: 'put',
headers: {
'Content-Type': 'application/octet-stream',
'Transfer-Encoding': 'chunked'
},
multipart : [
{ body: fs.createReadStream(localFile) }
]
};
失败了,我不知道我要去哪里错了。如何使用节点请求从 CURL 重现“--upload-file”参数?