gpt4 book ai didi

javascript - Firebase云函数: Error: EISDIR: illegal operation on a directory

转载 作者:行者123 更新时间:2023-12-01 00:21:05 27 4
gpt4 key购买 nike

我正在尝试从网址下载图像,然后将其上传到我的 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' }

我做错了什么?

提前致谢!

最佳答案

path您提供给方法 upload应该是一个文件而不是目录。

upload(pathString, optionsopt, callbackopt) → {Promise.<UploadResponse>}

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

关于javascript - Firebase云函数: Error: EISDIR: illegal operation on a directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59423871/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com