node.js - 从图像 url 将图像上传到谷歌驱动器
问题描述
嗨,我正在用节点制作刮刀
我不想在服务器中保存任何文件,所以我正在尝试从 url 上传图像
我正在使用 axios 来获取图像并使用 googleapis 来上传它。
这是我的代码:
const oauth2client = new google.auth.OAuth2(
config.CLIENT_ID,
config.CLIENT_SECRET,
config.REDIRECT_URI
)
oauth2client.setCredentials({'refresh_token': config.REFRESH_TOKEN})
const drive = google.drive({
version: 'v3',
auth: oauth2client
})
async function UploadImage(){
var image = await axios
.get('https://www.somepage.com/image.jpg', {
responseType: 'stream'
}).then(response => response.data)
var response = await drive.files.create({
requestBody: {
name: 'image.jpg',
mimeType: 'image/jpeg',
},
media: {
mimeType: 'image/jpeg',
body: image
}
});
}
无论如何要从 axios 流响应创建 readerStrem 吗?
解决方案
推荐阅读
- c# - 通过 rotativa 在本地获取 PDF 时,为什么我不能通过在线下载 PDF?
- gluon - 有没有办法使用胶子地图进行导航或方向?
- c# - 更改脚本的一个属性值,使其影响该脚本附加到的所有游戏对象
- excel - 从 Excel 通过 Outlook 发送邮件
- spring-boot - spring boot 2.1.x 是否支持 yaml 1.2 规范
- macos - 如何在mac中获得鼠标下的顶部窗口
- angular - 如何测试跨度的幻影?
- angular - 在 ngFor 选择选项中,如何在 onChange 发送特定对象属性的值
- node.js - 如何修复用于“google-cloud/translate”的模块nodeJS“googleauth.js”的“child_process”和“fs”依赖项
- elixir - 使用 Elixir 将 Enum 转换为 Flow