【发布时间】:2020-04-12 21:15:50
【问题描述】:
我正在尝试从 url 下载图像,然后将其上传到我的 firebase 云存储。 这是我正在使用的代码。
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
const download = require('image-downloader');
const tmp = require('tmp');
export const downloadFunction = functions.https.onCall(async (data, context) => {
var bucket = admin.storage().bucket();
await tmp.dir(async function _tempDirCreated(err: any, path: any) {
if (err) throw err;
const options = {
url: 'theUrlIWantToPutInTheStorage',
dest: path,
}
console.log('Dir: ', path);
await download.image(options)
.then(async () => {
console.log('Saved');
await bucket.upload(path, {
destination: "testfolder/test.jpg",
metadata: "metadata",
});
})
.catch((err2: any) => console.error(err2))
});
});
但是从 firebase 控制台(日志)我得到这个错误:
{ Error: EISDIR: illegal operation on a directory, read errno: -21, code: 'EISDIR', syscall: 'read' }
我做错了什么?
提前致谢!
【问题讨论】:
-
这个console.log('Saved')出现在日志中了吗?
-
“testfolder/test.jpg”是目录吗?
标签: javascript node.js typescript firebase google-cloud-functions