簡體   English   中英

Firebase 雲功能:錯誤:EISDIR:對目錄的非法操作

[英]Firebase cloud function: Error: EISDIR: illegal operation on a directory

我正在嘗試從 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' }

我究竟做錯了什么?

提前致謝!

您提供給方法uploadpath應該是文件而不是目錄。

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

將文件上傳到存儲桶。 這是一種包裝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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM