How to move files with firebase storage?

felipepastorelima picture felipepastorelima · Jul 27, 2016 · Viewed 8.9k times · Source

Is there a way to move files with firebase.storage()?

Example: user1/public/image.jpg to user1/private/image.jpg

Answer

Mike McDonald picture Mike McDonald · Jul 27, 2016

Since Firebase Storage is backed by Google Cloud Storage, you can use GCS's rewrite API (docs) or gsutil mv (docs).

Also, an example of move (docs) in GCloud Node follows:

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.
});