本文介绍了Firebase云功能:错误:EISDIR:对目录的非法操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从URL下载图像,然后将其上传到我的Firebase云存储中.这是我正在使用的代码.
I'm trying to download an image from an url and then uploading it to my firebase cloud storage.This is the code i'm using.
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控制台(日志)中,出现此错误:
But from the firebase console (logs) I get this error:
{ Error: EISDIR: illegal operation on a directory, read errno: -21, code: 'EISDIR', syscall: 'read' }
我在做什么错了?
提前谢谢!
推荐答案
您为方法upload
提供的path
应该是文件,而不是目录.
The path
that you provide to the method upload
should be a file and not a directory.
将文件上传到存储桶.这是包装File#createWriteStream
的便捷方法.
Upload a file to the bucket. This is a convenience method that wraps File#createWriteStream
.
示例:
const options = {
destination: 'new-image.png',
resumable: true,
validation: 'crc32c',
metadata: {
metadata: {
event: 'Fall trip to the zoo'
}
}
};
bucket.upload('local-image.png', options, function(err, file) {
// Your bucket now contains:
// - "new-image.png" (with the contents of `local-image.png')
// `file` is an instance of a File object that refers to your new file.
});
https://googleapis.dev/nodejs/storage/latest/Bucket.html
这篇关于Firebase云功能:错误:EISDIR:对目录的非法操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!