node.js - 使用 Node.js 将照片从 Google Drive 上传到 AWS S3
问题描述
要求是将照片从公共谷歌驱动器文件夹上传到 s3。
从谷歌驱动器获取图像列表的代码
module.exports.fetchImageDetails = async (fileId) => new Promise(async (res, rej) =>
{
const token = await googleUtil();
const drive = google.drive('v2');
drive.files.get(
{
auth: token,
fileId: `${fileId}`,
},
(err, response) => {
if (err) {
console.log(`The API returned an error: ${err}`);
rej(err);
}
res(response.data);
},
);
});
迭代图像
for (file of fetchedFilesInFolder.files) {
uploadStatus = await s3Helper.uploadImage(
process.env.MEDIA_S3_BUCKET,
url,
fileDetails.webContentLink
);
}
上传到 S3: const options = { uri: url, encoding: null, }; 常量主体 = 等待请求(选项);
const uploadResult = await s3
.upload({
Bucket: bucket,
Key: path,
Body: body,
})
.promise();
此代码有时有效,有时无效。很多时候,上传到 S3 上的图像不是有效的图像。
我们真的不确定,发生了什么。
请注意:图像大小约为 6 MB。此外,当我们访问 URL ( https://drive.google.com/uc?id= <file_id>&export=download )时,默认情况下,谷歌驱动器webContentLink 会下载图像。这可能是问题的根本原因吗?此外,从链接中删除&export=download并不奇怪,因为https://drive.google.com/uc?id= <file_id>被重定向到另一个链接。const body = await request(options);
我们已经为此花费了足够的时间,但无法修复它。
解决方案
推荐阅读
- reactjs - 在 Meteorjs 中显示最新创建的用户和角色时的 Pub-Sub 问题
- mysql - 想要更新数据库中输入的条目。我有代码并显示错误:
- r - R在打开netcdf文件时崩溃
- rest-assured - 放心:- 从使用 Pathparam 和 FormParam 创建的 Post 请求中获得 404 响应
- json - 使用nodejs获取带有标头的json
- javascript - 散点图缩放在 d3.js 中无法正常工作
- html - 如何将父 div 的高度设置为具有位置的子 div:绝对
- python - 如何随意停止和启动线程
- javascript - 为什么这不是一个完美的正方形?
- javascript - 我在 ng-repeat 中使用了一个函数,但它的重复次数比数组的总长度多很多倍