One-drive-api : body 必须是字符串
One-drive-api : body must be a string
我正在使用库 one-drive-api 并尝试实现从一个文件夹到另一个文件夹的 meve 项目
这是我的代码
exports.moveItem = (req, res) => {
let { item_id, move_to_id, new_name } = req.body;
oneDriveAPI.items
.customEndpoint({
accessToken: accessToken,
URL: "/me/drive/items/"+item_id,
method: 'PATCH',
body: {
parentReference: {
id: move_to_id},
},
name: new_name,
},
})
.then((r) => {
res.status(200).send({ drives: r });
})
.catch((e) => {
res.status(500).send({ error: e.message });
});
};
我遇到了这个错误
{
"error": "The `body` option must be a stream.Readable, string or Buffer"
}
您应该能够通过预先对正文进行字符串化来使其工作。
body: JSON.stringify({
parentReference: {
id: move_to_id},
},
name: new_name,
}),
看起来这是来自 got
库的错误,您的 onedrive-api
包正在使用该库。传入字符串 应该 没问题,但如果不是,那么 onedrive-api 包 configures the got
request
的方式可能有问题
你可以试试这个:
let { item_id, move_to_id, new_name } = req.body;
let body_req = { parentReference: { id: move_to_id } };
let stringified = JSON.stringify(body_req);
let b = Buffer.from(stringified);
oneDriveAPI.items
.customEndpoint({
accessToken: accessToken,
url: `/me/drive/items/${item_id}`,
method: 'PATCH',
body: b,
})
.then((r) => {
res.status(200).send({ moved: r });
})
.catch((e) => {
res.status(500).send({ error: e.message });
});
我正在使用库 one-drive-api 并尝试实现从一个文件夹到另一个文件夹的 meve 项目 这是我的代码
exports.moveItem = (req, res) => {
let { item_id, move_to_id, new_name } = req.body;
oneDriveAPI.items
.customEndpoint({
accessToken: accessToken,
URL: "/me/drive/items/"+item_id,
method: 'PATCH',
body: {
parentReference: {
id: move_to_id},
},
name: new_name,
},
})
.then((r) => {
res.status(200).send({ drives: r });
})
.catch((e) => {
res.status(500).send({ error: e.message });
});
};
我遇到了这个错误
{
"error": "The `body` option must be a stream.Readable, string or Buffer"
}
您应该能够通过预先对正文进行字符串化来使其工作。
body: JSON.stringify({
parentReference: {
id: move_to_id},
},
name: new_name,
}),
看起来这是来自 got
库的错误,您的 onedrive-api
包正在使用该库。传入字符串 应该 没问题,但如果不是,那么 onedrive-api 包 configures the got
request
你可以试试这个:
let { item_id, move_to_id, new_name } = req.body;
let body_req = { parentReference: { id: move_to_id } };
let stringified = JSON.stringify(body_req);
let b = Buffer.from(stringified);
oneDriveAPI.items
.customEndpoint({
accessToken: accessToken,
url: `/me/drive/items/${item_id}`,
method: 'PATCH',
body: b,
})
.then((r) => {
res.status(200).send({ moved: r });
})
.catch((e) => {
res.status(500).send({ error: e.message });
});