Firebase storage: file().move is not implemented?

Viewed 243

I'm developing locally with firebase emulator.

The front app create a project with some files uploaded to a 'tmp/' folder in storage bucket.

I need to move the uploaded files to the project folder once the project is saved. But when doing (a cloud function)

const storage = new Storage();
// also tried:
// const storage = admin.storage();

const bucket = storage.bucket(DEFAULT_BUCKET);
const destRoot = `${project.id}/files`;

// `tmpFiles` is an array of file paths
const movedfiles = await Promise.all(
  tmpFiles.map((file: string) =>
    bucket
      .file(`tmp/${file}`) 
      .move(`${destRoot}/${file}`)
      .then((result) => result[0].publicUrl())
      .catch(console.log)
  )
);

I got this error ApiError: file#copy failed with an error - Not Implemented

So it's no possible to move storage files for now?

1 Answers

The Firebase emulators typically only/first implement operations that are also possible in the client-side SDK. Since the client-side SDK for Cloud Storage doesn't have an API to move files, the operation is (currently) also not implemented in the emulator when using the Admin SDK.

This specific feature is being tracked on the Github repo as #3751, so I recommend checking there for updates, or submitting a PR adding the functionality.

Related