Skip to content

Storage: file.copy, file.move(, others?) don't accept "gs://" URLs #1395

Description

@zbjornson

I was rather surprised when this command:

bucket.file("foo").copy("gs://otherbucket/something", cb)

created an object in the original bucket in a "gs:/" subdirectory. I see how to do what I want by passing a file or bucket instead of a string, but it seems like this could easily be supported with something like this:

--- lib/storage/file.js
+++ lib/storage/file.js
@@ File.prototype.copy = function(destination, callback) { @@
  if (is.string(destination)) {
+   if (destination.startsWith("gs://") {
+     var parsed = /^gs\:\/\/([a-z_\.\-]+)\/(.+)$/.exec(destination);
+     // assert parsed.length === 3
+     destBucket = parsed[1];
+     destName = parsed[2];
+   } else {
+     destBucket = this.bucket;
+     destName = destination;
+   }
-   destBucket = this.bucket;
-   destName = destination;
  } else if (destination.constructor &&

(Happy to make a PR with something like that.)

Activity

  1. stephenplusplus commented on Jun 26, 2016

    @stephenplusplus
    Contributor

    I'm totally cool with that. A PR would be great! Only note is to use indexOf instead of startsWith since we still support 0.12. Thanks!

  2. zbjornson commented on Jun 28, 2016

    @zbjornson
    ContributorAuthor

    Thanks. Heading out of town, probably won't get to a PR until ~10 July.

  3. stephenplusplus commented on Jun 29, 2016

    @stephenplusplus
    Contributor

    Sounds good, safe travels!

  4. added a commit that references this issue on Jul 12, 2016
    79e0e28
  5. added 2 commits that reference this issue on Feb 3, 2026
    79b1a17
    161eb62
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions