【发布时间】:2018-12-05 07:23:58
【问题描述】:
如何将文件夹中的所有文件无循环上传到 Google Storage Cloud。 在这里,我尝试使用 C# 上传一个文件:
public async Task<ActionResult> Upload(IFormFile file)
{
string contentRootPath = _hostingEnvironment.ContentRootPath;
var credential = GoogleCredential.FromJson(System.IO.File.ReadAllText(contentRootPath + "/credentials.json"));
StorageClient storageClient = StorageClient.Create(credential);
var objectName = MakeObjectName();
var imageObject = await storageClient.UploadObjectAsync(
bucket: CloudConfig.BUCKET,
objectName: objectName,
contentType: file.ContentType,
source: file.OpenReadStream(),
options: new UploadObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead }
);
return Ok(new DropzoneInfo { Name = file.FileName, ObjectName = objectName, Link = imageObject.MediaLink, Size = file.Length});
}
【问题讨论】:
-
你显示的代码有问题吗?
-
代码没问题。仅作为示例。
-
那你能详细说明一下这个扩展到多个文件的问题吗?
-
我只是想对块上传到谷歌云存储的代码提出质疑。并非所有代码都在行动中。
-
您的问题到底是什么?目前我看到了几种可能性:a)您想知道如何获取目录中的文件列表。 b) 你想知道如何循环上传每个文件的列表。