How to upload all files in folder to Google Storage Cloud without loop. Here I try use C# with one file upload :
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});
}
You have a controller action that accepts a single uploaded file. Use a List<IFormFile>
in your controller action - see this answer: Submitting multiple files to ASP.NET controller accepting an ICollection<IFormFile>
There is an attribute for uploading directories: <input type="file" webkitdirectory>
( How do I use Google Chrome 11's Upload Folder feature in my own code? )
These browsers support it: Edge, Safari, Firefox, Chrome, Opera ( https://caniuse.com/#feat=input-file-directory )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.