renaming files in Google Cloud Storage?

◇◆丶佛笑我妖孽 提交于 2019-12-10 21:05:49

问题


Can you rename files in Google Cloud Storage?

I am letting users upload photos, but I want to give them the ability to edit the photo, at least by changing the name they uploaded it with. I am using Javascript through Node.js.

Thanks!


回答1:


This command:

gsutil mv gs://my_bucket/olddir gs://my_bucket/newdir

will do the job. If you have a large number of files you need to do a multi-processing move, so use this command:

gsutil -m mv gs://my_bucket/olddir gs://my_bucket/newdir

You can find this information in the docs.




回答2:



Here is Python function performs a multi-threaded/multi-processing move:

from subprocess import call, CalledProcessError

def rename_object(self, old_dir, new_dir):
    base_cmd = ["gsutil", "-m", "mv"]
    old_path = "gs://{}".format(old_dir)
    new_path = "gs://{}".format(new_dir)
    cmd = base_cmd + [old_path, new_path]
    try:
        call(cmd)
    except CalledProcessError as e:
        print e


来源:https://stackoverflow.com/questions/24811645/renaming-files-in-google-cloud-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!