Asp.net MVC: upload multiple image files?
up vote
17
down vote
favorite
is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple files by clicking one button?
I used file upload in ajaxtoolbox in webform before and like how it works. Is there a similar way in MVC? or, is there a existing control that can do this well? free control is better, but it is ok even it costs some $.
Thanks
asp.net-mvc asp.net-mvc-4 file-upload image-uploading
add a comment |
up vote
17
down vote
favorite
is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple files by clicking one button?
I used file upload in ajaxtoolbox in webform before and like how it works. Is there a similar way in MVC? or, is there a existing control that can do this well? free control is better, but it is ok even it costs some $.
Thanks
asp.net-mvc asp.net-mvc-4 file-upload image-uploading
1
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
1
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42
add a comment |
up vote
17
down vote
favorite
up vote
17
down vote
favorite
is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple files by clicking one button?
I used file upload in ajaxtoolbox in webform before and like how it works. Is there a similar way in MVC? or, is there a existing control that can do this well? free control is better, but it is ok even it costs some $.
Thanks
asp.net-mvc asp.net-mvc-4 file-upload image-uploading
is there a good example of how to upload multiple image files in asp.net mvc? I know we can use HttpPostedFileBase to upload one file. Is there a way to upload multiple files by clicking one button?
I used file upload in ajaxtoolbox in webform before and like how it works. Is there a similar way in MVC? or, is there a existing control that can do this well? free control is better, but it is ok even it costs some $.
Thanks
asp.net-mvc asp.net-mvc-4 file-upload image-uploading
asp.net-mvc asp.net-mvc-4 file-upload image-uploading
asked Sep 10 '14 at 18:04
urlreader
3,33743257
3,33743257
1
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
1
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42
add a comment |
1
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
1
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42
1
1
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
1
1
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42
add a comment |
4 Answers
4
active
oldest
votes
up vote
4
down vote
accepted
Use this jQuery plugin
just include plugin js files, create tag:
<input type='file' multiple id='fileUpload' name="files" data-url="@Url.Action("Upload","Home")" />
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want.
Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
add a comment |
up vote
21
down vote
You could implement an action with POST
http verb to that receive a collection of HttpPostedFileBase
and save all files, for sample:
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
Alternatively, you could read Request.Files
and do the same job,
[HttpPost]
public ActionResult Upload()
{
foreach (var file in Request.Files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
See Also
- Single File Upload to Multiple File Upload in MVC
- Uploading a File (Or Files) With ASP.NET MVC
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
add a comment |
up vote
1
down vote
I'm using this one. https://www.fyneworks.com/jquery/multiple-file-upload/
<input type="file" name="file" class="multiple" />
[HttpPost]
public ActionResult Upload()
{
if (Request.Files.Count > 0)
{
foreach(var file in Request.Files) { }
}
return View();
}
add a comment |
up vote
0
down vote
Some of the basic bits required for file uploads
Notice keyword: multiple in input element AND
multipart in form element
HTML Side
@using (Html.BeginForm("MyUpload", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="myFiles" multiple />
<button class="btn btn-default">Upload</button>
}
Controller
[HttpPost]
public ActionResult MyUpload(IEnumerable<HttpPostedFileBase> myFiles)
{
foreach (var file in myFiles)
{
if (file != null && file.ContentLength > 0)
{
//handle files;
}
}
return View();
}
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Use this jQuery plugin
just include plugin js files, create tag:
<input type='file' multiple id='fileUpload' name="files" data-url="@Url.Action("Upload","Home")" />
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want.
Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
add a comment |
up vote
4
down vote
accepted
Use this jQuery plugin
just include plugin js files, create tag:
<input type='file' multiple id='fileUpload' name="files" data-url="@Url.Action("Upload","Home")" />
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want.
Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Use this jQuery plugin
just include plugin js files, create tag:
<input type='file' multiple id='fileUpload' name="files" data-url="@Url.Action("Upload","Home")" />
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want.
Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}
Use this jQuery plugin
just include plugin js files, create tag:
<input type='file' multiple id='fileUpload' name="files" data-url="@Url.Action("Upload","Home")" />
(Except IE9 it is not allowing select multiple files in select dialog)
Add some JavaScript:
$(function () {
$('#fileUpload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
});
});
In controller action just check Request.Files and do whatever you want.
Here is a good documentation
[HttpPost]
public JsonResult Upload()
{
foreach (var file in Request.Files)
{
if(file.ContentLength > 0)
{
file.SaveAs(Server.MapPath("~/Upload/" + file.FileName));
}
}
return Json(new { result = true });
}
edited Sep 20 '15 at 21:59
Chris Schiffhauer
12.7k126378
12.7k126378
answered Sep 10 '14 at 18:55
aleha
4,55911826
4,55911826
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
add a comment |
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
using this plugin, a basic example can be found here : github.com/blueimp/jQuery-File-Upload/wiki/Basic-plugin
– John Marston
Mar 3 '17 at 11:42
add a comment |
up vote
21
down vote
You could implement an action with POST
http verb to that receive a collection of HttpPostedFileBase
and save all files, for sample:
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
Alternatively, you could read Request.Files
and do the same job,
[HttpPost]
public ActionResult Upload()
{
foreach (var file in Request.Files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
See Also
- Single File Upload to Multiple File Upload in MVC
- Uploading a File (Or Files) With ASP.NET MVC
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
add a comment |
up vote
21
down vote
You could implement an action with POST
http verb to that receive a collection of HttpPostedFileBase
and save all files, for sample:
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
Alternatively, you could read Request.Files
and do the same job,
[HttpPost]
public ActionResult Upload()
{
foreach (var file in Request.Files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
See Also
- Single File Upload to Multiple File Upload in MVC
- Uploading a File (Or Files) With ASP.NET MVC
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
add a comment |
up vote
21
down vote
up vote
21
down vote
You could implement an action with POST
http verb to that receive a collection of HttpPostedFileBase
and save all files, for sample:
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
Alternatively, you could read Request.Files
and do the same job,
[HttpPost]
public ActionResult Upload()
{
foreach (var file in Request.Files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
See Also
- Single File Upload to Multiple File Upload in MVC
- Uploading a File (Or Files) With ASP.NET MVC
You could implement an action with POST
http verb to that receive a collection of HttpPostedFileBase
and save all files, for sample:
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
Alternatively, you could read Request.Files
and do the same job,
[HttpPost]
public ActionResult Upload()
{
foreach (var file in Request.Files)
{
file.SaveAs(Server.MapPath("~/Update/" + file.FileName));
}
return View();
}
See Also
- Single File Upload to Multiple File Upload in MVC
- Uploading a File (Or Files) With ASP.NET MVC
answered Sep 10 '14 at 20:31
Felipe Oriani
27.7k1595155
27.7k1595155
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
add a comment |
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
Thanks a lot for the links, it really helped me
– magorich
Dec 7 '16 at 0:03
add a comment |
up vote
1
down vote
I'm using this one. https://www.fyneworks.com/jquery/multiple-file-upload/
<input type="file" name="file" class="multiple" />
[HttpPost]
public ActionResult Upload()
{
if (Request.Files.Count > 0)
{
foreach(var file in Request.Files) { }
}
return View();
}
add a comment |
up vote
1
down vote
I'm using this one. https://www.fyneworks.com/jquery/multiple-file-upload/
<input type="file" name="file" class="multiple" />
[HttpPost]
public ActionResult Upload()
{
if (Request.Files.Count > 0)
{
foreach(var file in Request.Files) { }
}
return View();
}
add a comment |
up vote
1
down vote
up vote
1
down vote
I'm using this one. https://www.fyneworks.com/jquery/multiple-file-upload/
<input type="file" name="file" class="multiple" />
[HttpPost]
public ActionResult Upload()
{
if (Request.Files.Count > 0)
{
foreach(var file in Request.Files) { }
}
return View();
}
I'm using this one. https://www.fyneworks.com/jquery/multiple-file-upload/
<input type="file" name="file" class="multiple" />
[HttpPost]
public ActionResult Upload()
{
if (Request.Files.Count > 0)
{
foreach(var file in Request.Files) { }
}
return View();
}
answered Sep 10 '14 at 22:17
Kadir
1,80912642
1,80912642
add a comment |
add a comment |
up vote
0
down vote
Some of the basic bits required for file uploads
Notice keyword: multiple in input element AND
multipart in form element
HTML Side
@using (Html.BeginForm("MyUpload", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="myFiles" multiple />
<button class="btn btn-default">Upload</button>
}
Controller
[HttpPost]
public ActionResult MyUpload(IEnumerable<HttpPostedFileBase> myFiles)
{
foreach (var file in myFiles)
{
if (file != null && file.ContentLength > 0)
{
//handle files;
}
}
return View();
}
add a comment |
up vote
0
down vote
Some of the basic bits required for file uploads
Notice keyword: multiple in input element AND
multipart in form element
HTML Side
@using (Html.BeginForm("MyUpload", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="myFiles" multiple />
<button class="btn btn-default">Upload</button>
}
Controller
[HttpPost]
public ActionResult MyUpload(IEnumerable<HttpPostedFileBase> myFiles)
{
foreach (var file in myFiles)
{
if (file != null && file.ContentLength > 0)
{
//handle files;
}
}
return View();
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Some of the basic bits required for file uploads
Notice keyword: multiple in input element AND
multipart in form element
HTML Side
@using (Html.BeginForm("MyUpload", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="myFiles" multiple />
<button class="btn btn-default">Upload</button>
}
Controller
[HttpPost]
public ActionResult MyUpload(IEnumerable<HttpPostedFileBase> myFiles)
{
foreach (var file in myFiles)
{
if (file != null && file.ContentLength > 0)
{
//handle files;
}
}
return View();
}
Some of the basic bits required for file uploads
Notice keyword: multiple in input element AND
multipart in form element
HTML Side
@using (Html.BeginForm("MyUpload", "MyController", FormMethod.Post, new { enctype = "multipart/form-data" })) {
<input type="file" name="myFiles" multiple />
<button class="btn btn-default">Upload</button>
}
Controller
[HttpPost]
public ActionResult MyUpload(IEnumerable<HttpPostedFileBase> myFiles)
{
foreach (var file in myFiles)
{
if (file != null && file.ContentLength > 0)
{
//handle files;
}
}
return View();
}
answered Jul 3 '17 at 13:15
Moji
3,14322628
3,14322628
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25772134%2fasp-net-mvc-upload-multiple-image-files%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
we used plupload.com at my last job for multiple uploads
– Matt Bodily
Sep 10 '14 at 18:26
is there a simple example of how to use it in asp.net MVC? thanks.
– urlreader
Sep 10 '14 at 18:47
1
I don't have access to that code base anymore. Here is an example I found googling pluploadmvc4demo.codeplex.com
– Matt Bodily
Sep 10 '14 at 19:42