如何使用firebase存储移动文件?

fel*_*ima 10 firebase firebase-storage

有没有办法用firebase.storage()移动文件?

示例:user1/public/image.jpg到user1/private/image.jpg

Ant*_*ort 10

自 2022 年 3 月 29 日起,可以通过以下方式直接调用“move”函数:

import * as functions from "firebase-functions";
import {getStorage} from "firebase-admin/storage";

export const triggerStorage = functions
  .storage
  .object()
  .onFinalize(async (object) => {
    const bucket = getStorage().bucket(object.bucket);
    const destPath = "user1/private/image.jpg";
    await bucket.file(object.name).move(destPath);
  });
Run Code Online (Sandbox Code Playgroud)


Mik*_*ald 9

由于Firebase存储由Google云端存储支持,因此您可以使用GCS的rewriteAPI(文档)或gsutil mv(文档).

此外,GCloud Node中的move(docs)示例如下:

var bucket = gcs.bucket('my-bucket');
var file = bucket.file('my-image.png');
var newLocation = 'gs://another-bucket/my-image-new.png';
file.move(newLocation, function(err, destinationFile, apiResponse) {
  // `my-bucket` no longer contains:
  // - "my-image.png"
  //
  // `another-bucket` now contains:
  // - "my-image-new.png"

  // `destinationFile` is an instance of a File object that refers to your
  // new file.
});
Run Code Online (Sandbox Code Playgroud)


Sah*_*ana 6

没有这种方法可以移动到其他位置,而是可以下载然后将其放到其他位置并删除以前的位置.