我想使用 Go 将文件上传到谷歌云存储桶子目录。我找到的唯一引用代码是link .
wc := client.Bucket(bucket).Object(object).NewWriter(ctx)
object
这是您的文件名的字符串,但不允许使用文件路径。当我使用像 /path/filename
这样的文件名时,它会抛出以下错误.仅当您使用 filename
时才有效.connect: can't assign requested address
以前我使用 node.js,它工作正常。
await bucket.upload(filePath, { destination: `path/filename`, resumable:false });
我怎样才能用 Go 实现呢?
最佳答案
您无法将文件上传到 Google Cloud Storage Bucket 子目录,因为 Subdirectory
的概念GCS 上不存在。
Google Cloud Storage 对象是一个平面命名空间。
因此,在 GCS 中,您只有存储桶和对象。
在这里,您可以找到有关 gsutil 如何提供分层文件树错觉的更多详细信息:
How Subdirectories Work
关于go - 如何将文件上传到 Google Cloud Storage Bucket 子目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64025960/