我正在尝试在OneDrive上执行分段上传。执行以下代码:
function multipartUpload() {
var boundary = '-------48492abalalal22200';
var delimiter = "\r\n--" + boundary + "\r\n";
var close_delim = "\r\n--" + boundary + "--";
var metadata = prepMetadata()
metadata['@microsoft.graph.sourceUrl'] = 'cid:content'
metadata.name = saveTo.fileName
metadata.file = {}
var multipartRequestBody =
delimiter +
'Content-ID: <metadata>\r\n' +
'Content-Type: application/json\r\n' +
'\r\n' +
JSON.stringify(metadata) +
delimiter +
'Content-ID: <content>\r\n' +
'Content-Type: ' + contentType + '\r\n' +
'\r\n'
uploadReq.once('res', function(res, body) {
if(res.statusCode != 200)
return self.emit('res', {
code: res.statusCode,
message: res.statusMessage
})
var metadata = parse(body)
if(metadata.error)
return self.emit('res', metadata.error);
self.emit('res', null, {
doneWithFile: true
});
})
if(saveTo.parentID == '/')
var item = '/root/children'
else
var item = '/items/' + saveTo.parentID + '/children'
self.writable = uploadReq.issue({
options: {
hostname: hostname,
path: basePath + item,
method: 'POST',
headers: {
Authorization: 'Bearer ' + accessToken,
'Content-Type': 'multipart/related; boundary=' + boundary
}
}
});
self.writable.write(multipartRequestBody)
var endUpload = self.writable.end.bind(self.writable)
self.writable.end = function() {
endUpload(close_delim)
}
}
我正在写自己的身体。可写在其他地方。
据我所知,无论提供何种元数据,都会将其添加到儿童收藏中。但这是错误:
{
"error": {
"code": "BadRequest",
"message": "Entity only allows writes with a JSON Content-Type header.",
"innerError": {
"request-id": "c98da348f31-325659b2d76d",
"date": "2017-04-17T15:25:51"
}
}
}
我不知道我做错了什么。
请帮忙。