Upload Multiple images to azure and retrieve using MVC
This is my code for Uploading multiple images to azure,
This is my code,I am running this code Getting the following Error:
Error 2 foreach statement cannot operate on variables of type 'System.Web.HttpPostedFileBase' because 'System.Web.HttpPostedFileBase' does not contain a public definition for 'GetEnumerator' D:\DRIVE(D)\mindstick(Practice\NotousProducts\MvcWebRole1\Controllers\ProductsController.cs 64 21 MvcWebRole1
View:
@model MvcWebRole1.Models.Product
@{
ViewBag.Title = "Create";
}
<h2>Create</h2>
@using (Html.BeginForm("Create","Products",FormMethod.Post, new { enctype = "multipart/form-data" })) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Product</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Name)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Price)
@Html.ValidationMessageFor(model => model.Price)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Image)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image)*@
<input type="file" name="fileBase" id="filebase1" />
@Html.ValidationMessageFor(model => model.Image)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Image1)
</div>
<div class="editor-field">
@*@Html.EditorFor(model => model.Image1)*@
<input type="file" name="fileBase" id="filebase2" />
@Html.ValidationMessageFor(model => model.Image1)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
[HttpPost]
public ActionResult Create(Product p,HttpPostedFileBase fileBase)
{
if (fileBase.ContentLength > 0)
{
foreach (IEnumerable<HttpPostedFileBase> image in fileBase)
{
// Retrieve a reference to a container
CloudBlobContainer blobContainer = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob = blobContainer.GetBlobReference(fileBase.FileName);
// Create or overwrite the "myblob" blob with contents from a local file
blob.UploadFromStream(fileBase.InputStream);
}
}
}
//secode
CloudBlobContainer blobContainer1 =_myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob1 = blobContainer1.GetBlobReference(fileBase.FileName);
CloudBlobContainer blobContainer112 = _myBlobStorageService.GetCloudBlobContainer();
CloudBlob blob112 = blobContainer112.GetBlobReference(fileBase.FileName);
List<string> blobs = new List<string>();
// Loop over blobs within the container and output the URI to each of them
foreach (var blobItem in blobContainer1.ListBlobs())
blobs.Add(blobItem.Uri.ToString());
// TODO: Add insert logic here
//Product p1 = new Product();
p.Image = blob1.Uri.ToString();
p.Image1 = blob112.Uri.ToString();
db.Products.InsertOnSubmit(p);
db.SubmitChanges();
return RedirectToAction("Index");
}