使用 Expect 发送 curl --upload-file header -> Node.js

Send curl with Expect --upload-file header -> Node.js

我正在努力将文件上传到 Autodesk View and Data API,但我不知道如何通过 http 发送 curl 或请求 lib。具体来说,我不知道如何设置 expect header.

这是我尝试发送的 curl

curl --header "Authorization: Bearer nqjy2YlqYVi9VqBLjKinixIkhDRA" --header "Content-Length: 199233" \
-H "Content-Type:application/octet-stream" --header "Expect:" --upload-file "./Torus.obj" 
-X PUT https://developer.api.autodesk.com/oss/v1/buckets/mybucket/objects/Torus.obj -k

每次我收到 417 http 响应。有人可以帮我开发 Node.js 中的功能吗?

非常感谢。

---更新---- 固定:

var xhr = new XMLHttpRequest();

xhr.open('PUT',
    'https://developer.api.autodesk.com/oss/v1/buckets/' + GLOBAL.AutodeskBucket + '/objects/' + file.name,
    true);

xhr.setRequestHeader(
  'Authorization',
  'Bearer ' + GLOBAL.AutodeskToken.access_token);

xhr.setRequestHeader(
  'Content-Type',
  'application/stream');

xhr.onload = function () {
    var response = JSON.parse(xhr.responseText);
    response.file = file;
    callback(response);
};


var reader = new FileReader();

// `onload` as listener
reader.addEventListener('load', function (ev) {
  xhr.send(ev.target.result);
});

var file = new File(path.dirname(require.main.filename) + '/files/' + file.name);

reader.readAsBinaryString(file);

以防万一,您也可以在 https://developer.autodesk.com/api/view-and-data-api/#oss-bucket-and-object-api-v1-0

查看文档