繁体   English   中英

如何在没有 rclone 的情况下以编程方式直接从 Digital Ocean Storage 上传到 Google Cloud Storage

[英]How to upload from Digital Ocean Storage to Google Cloud Storage, directly, programatically without rclone

我想在没有 rclone 的情况下以编程方式将文件从 Digital Ocean Storage 迁移到 Google Cloud Storage。

我知道驻留在数字海洋存储(DOS)中的确切位置文件,并且我有谷歌云存储(GCS)的签名 url。

我如何修改以下代码,以便我可以将 DOS 文件直接复制到 GCS 而无需中间下载到我的计算机?

def upload_to_gcs_bucket(blob_name, path_to_file, bucket_name):
    """ Upload data to a bucket"""

    # Explicitly use service account credentials by specifying the private key
    # file.
    storage_client = storage.Client.from_service_account_json(
        'creds.json')

    #print(buckets = list(storage_client.list_buckets())

    bucket = storage_client.get_bucket(bucket_name)
    blob = bucket.blob(blob_name)
    blob.upload_from_filename(path_to_file)

    #returns a public url
    return blob.public_url

Google 的Storage Transfer Servivce应该是此类问题的答案(特别是因为DigitalOcean Spaces最喜欢 S3 兼容。但是 (.) 我认为(我不熟悉并且不确定)它不能用于此配置.

如果没有某种形式的中间传输,就无法将文件从源传输到目标,但您可以使用 memory 而不是使用文件存储作为中介。 Memory 通常比文件存储更受限制如果您希望同时运行多个传输,每个都会消耗一些存储量。

很奇怪您使用的是签名 URL。 通常,签名 URL 由第三方提供以限制对第三方存储桶的访问。 如果您拥有目标存储桶,那么直接从 Google 的客户端库之一(例如Python Client Library )使用 Google Cloud Storage 存储桶会更容易。

Python 示例包括从文件上传和从 memory上传。 如果您不想创建中间文件,最好将文件 stream 放入 Cloud Storage。 这是一个Python 的例子

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM