I have a site that uses BeginCollectionItem to create new Process Steps and within each process step it has a file upload. Ideally I'd like the file uploads to save to different Containers, as this will make it easier for when I then need to download the files.
However at the moment it is creating a Container for each collection item, but its putting all files in each one, I'd expect it to put each file in its corresponding container.
For the storage we're using Azure Storage Accounts.
Code is below:
The Partial View:
@using (Html.BeginCollectionItem("SectionInfo"))
{<div class="col-12 value-top pad-top"><input class="hidden-value" value="" name="SectionInfo[@ViewData["ContainerNoNum"]].valuematch"><h3>Due Date</h3>
@Html.EditorFor(m => m.DueDate)</div><div class="col-12 pad-top"><h3>Add files</h3><input type="file" name="files" multiple="multiple"></div><div class="col-12 pad-top"><h3>External Document Link</h3>
@Html.TextBoxFor(m => m.ExternalDocument)</div>
}
Controller:
[HttpPost]
public async Task<IActionResult> InstanceProcess(List<IFormFile> files, string InstanceId, [Bind(Prefix = "SectionInfo")]IEnumerable<ProcessOutput> secinf)
{
if (files.Count() > 0)
{
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(getid);
await container.CreateIfNotExistsAsync();
await container.SetPermissionsAsync(new BlobContainerPermissions
{
PublicAccess = BlobContainerPublicAccessType.Blob
});
foreach (var item in secinf)
{
foreach (var file in files)
{
CloudBlockBlob blockBlob = container.GetBlockBlobReference(item.valuematch +file.FileName);
await blockBlob.UploadFromStreamAsync(file.OpenReadStream());
}
}
}
_context.SaveChanges();
}