我正在为我的 Strapi 应用程序构建一个 CSV 导入器,其任务之一是从单元格读取图像 URL 并从该 URL 下载它并将其保存到媒体库。
代码如下所示:
const request = require('request').defaults({ encoding: null });
request.get(src, function (err, res, body) {
const fileName = src.split('/').pop();
strapi.plugins.upload.services.upload.upload({
files: {
path: body,
name: fileName,
type: res.headers['content-type'],
size: Number(res.headers['content-length']),
},
data: {
ref: 'products',
refId: data.itemID,
field: 'images'
}
});
});
Run Code Online (Sandbox Code Playgroud)
下载工作正常,我在回调body的变量中得到一个缓冲区request.get。但传递这个strapi.plugins.upload.services.upload.upload给我以下错误:
UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received <Buffer ff d8 ff e1 10 c1 …Run Code Online (Sandbox Code Playgroud)