nodeJS를 통해 파일을 드롭 박스에 업로드하려고합니다. 이 CURL 요청이 작동합니다.데이터 - 요청 이진 노드
curl -X POST https://content.dropboxapi.com/2/files/upload \
--header "Authorization: Bearer myToken" \
--header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
--header "Content-Type: application/octet-stream" \
--data-binary @fileName
나는 어떻게 자바 스크립트 코드로 번역 해야할지 모르겠다. 는 여기에 지금까지 수행 한 작업은 다음과 같습니다
var request = require('request')
var headers = {
"Authorization": "Bearer " + dropboxToken,
"Dropbox-API-Arg": {
"path": "/"+fileName, //nome sul drive
"mode": "add",
"autorename": true,
"mute": false
},
"Content-Type": "application/octet-stream"
}
var options = {
url: 'https://content.dropboxapi.com/2/files/upload',
method: 'POST',
headers: headers,
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
});
가 어떻게 업로드 할 파일을 선택하기 위해이 요청에서 data-binary
옵션을 포함합니까?
감사합니다. 당신이 readstream 한 다음 자바 스크립트의 보관 용 API와 통합하려는 경우는,
fs.createReadStream('/path/to/youfile').pipe(request.post(options).on('end', (done) => { console.log('success') }));
https://stackoverflow.com/a/4/495328/1757378 –