使用Node.js GCloud API在Google Cloud Storage中移动/重命名文件夹 [英] Move/rename folder in Google Cloud Storage using nodejs gcloud api

查看:118
本文介绍了使用Node.js GCloud API在Google Cloud Storage中移动/重命名文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用gcloud api重命名或移动Google云存储中的文件夹.

I am trying to rename or move a folder in google cloud storage using the gcloud api.

一个类似的问题说明了如何删除文件夹: 使用nodejs gcloud api在Google Cloud Storage中删除文件夹

A similar question explains how to delete a folder: Delete folder in Google Cloud Storage using nodejs gcloud api

但是如何重命名文件夹?或移至其他路径?

But how can one rename a folder? or move to another path?

推荐答案

您可以尝试执行以下操作:

You can try something like this:

'use strict'

var async = require('async')
var storage = require('@google-cloud/storage')()
var bucket = storage.bucket('stephen-has-a-new-bucket')

bucket.renameFolder = function(source, dest, callback) {
  bucket.getFiles({ prefix: source }, function(err, files) {
    if (err) return callback(err)

    async.eachLimit(files, 5, function(file, next) {
      file.move(file.name.replace(source, dest), next)
    }, callback)
  })
}

bucket.renameFolder('photos/cats', 'photos/dogs', console.log)

这篇关于使用Node.js GCloud API在Google Cloud Storage中移动/重命名文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆