@@ -79,6 +79,12 @@ var STORAGE_DOWNLOAD_BASE_URL = 'https://storage.googleapis.com';
7979 */
8080var STORAGE_UPLOAD_BASE_URL = 'https://www.googleapis.com/upload/storage/v1/b' ;
8181
82+ /**
83+ * @const {RegExp}
84+ * @private
85+ */
86+ var GS_URL_REGEXP = / ^ g s \: \/ \/ ( [ a - z 0 - 9 _ \. \- ] + ) \/ ( .+ ) $ / ;
87+
8288/*! Developer Documentation
8389 *
8490 * @param {module:storage/bucket } bucket - The Bucket instance this file is
@@ -284,7 +290,7 @@ nodeutil.inherits(File, ServiceObject);
284290/**
285291 * Copy this file to another file. By default, this will copy the file to the
286292 * same bucket, but you can choose to copy it to another Bucket by providing
287- * either a Bucket or File object.
293+ * a Bucket or File object or a URL starting with "gs://" .
288294 *
289295 * @resource [Objects: copy API Documentation]{@link https://cloud.google.com/storage/docs/json_api/v1/objects/copy}
290296 *
@@ -321,6 +327,22 @@ nodeutil.inherits(File, ServiceObject);
321327 * });
322328 *
323329 * //-
330+ * // If you pass in a string starting with "gs://" for the destination, the
331+ * // file is copied to the other bucket and under the new name provided.
332+ * //-
333+ * var newLocation = 'gs://another-bucket/my-image-copy.png';
334+ * file.copy(newLocation, function(err, copiedFile, apiResponse) {
335+ * // `my-bucket` still contains:
336+ * // - "my-image.png"
337+ * //
338+ * // `another-bucket` now contains:
339+ * // - "my-image-copy.png"
340+ *
341+ * // `copiedFile` is an instance of a File object that refers to your new
342+ * // file.
343+ * });
344+ *
345+ * //-
324346 * // If you pass in a Bucket object, the file will be copied to that bucket
325347 * // using the same name.
326348 * //-
@@ -366,8 +388,14 @@ File.prototype.copy = function(destination, callback) {
366388 var newFile ;
367389
368390 if ( is . string ( destination ) ) {
369- destBucket = this . bucket ;
370- destName = destination ;
391+ var parsedDestination = GS_URL_REGEXP . exec ( destination ) ;
392+ if ( parsedDestination !== null && parsedDestination . length === 3 ) {
393+ destBucket = this . storage . bucket ( parsedDestination [ 1 ] ) ;
394+ destName = parsedDestination [ 2 ] ;
395+ } else {
396+ destBucket = this . bucket ;
397+ destName = destination ;
398+ }
371399 } else if ( destination . constructor &&
372400 destination . constructor . name === 'Bucket' ) {
373401 destBucket = destination ;
@@ -1467,7 +1495,7 @@ File.prototype.makePublic = function(callback) {
14671495/**
14681496 * Move this file to another location. By default, this will move the file to
14691497 * the same bucket, but you can choose to move it to another Bucket by providing
1470- * either a Bucket or File object.
1498+ * a Bucket or File object or a URL beginning with "gs://" .
14711499 *
14721500 * **Warning**:
14731501 * There is currently no atomic `move` method in the Google Cloud Storage API,
@@ -1513,6 +1541,22 @@ File.prototype.makePublic = function(callback) {
15131541 * });
15141542 *
15151543 * //-
1544+ * // If you pass in a string starting with "gs://" for the destination, the
1545+ * // file is copied to the other bucket and under the new name provided.
1546+ * //-
1547+ * var newLocation = 'gs://another-bucket/my-image-new.png';
1548+ * file.move(newLocation, function(err, destinationFile, apiResponse) {
1549+ * // `my-bucket` no longer contains:
1550+ * // - "my-image.png"
1551+ * //
1552+ * // `another-bucket` now contains:
1553+ * // - "my-image-new.png"
1554+ *
1555+ * // `destinationFile` is an instance of a File object that refers to your
1556+ * // new file.
1557+ * });
1558+ *
1559+ * //-
15161560 * // If you pass in a Bucket object, the file will be moved to that bucket
15171561 * // using the same name.
15181562 * //-
0 commit comments