آپلود فایل ها با استفاده از PlUpload در Asp.Net Mvc
نویسنده: امیرحسین جلوداری
تاریخ: ۱۳۹۱/۰۶/۰۶ ۱۳:۴۳
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
<title>@ViewBag.Title</title>
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="../../plupload/js/jquery.plupload.queue/css/jquery.plupload.queue.css" rel="stylesheet" />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script>
<script src="../../plupload/js/plupload.full.js"></script>
<script src="../../plupload/js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script src="../../plupload/js/i18n/fa.js"></script>
@{
ViewBag.Title = "Uploading Files using PlUpload";
}
<h2>@ViewBag.Message</h2>
@using (Html.BeginForm("Post", "home", FormMethod.Post,
new { enctype = "multipart/form-data" }))
{
<div id="uploader">
<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p>
</div>
}
<script>
$(function () {
$("#uploader").pluploadQueue({
// General settings
runtimes: 'html5,gears,flash,silverlight,browserplus,html4',
url: '@Url.Action("Upload" , "Home")',
max_file_size: '10mb',
chunk_size: '1mb',
unique_names: true,
// Resize images on clientside if we can
resize: { width: 320, height: 240, quality: 90 },
// Specify what files to browse for
filters: [
{ title: "Image files", extensions: "jpg,gif,png" },
{ title: "Zip files", extensions: "zip" }
],
// Flash settings
flash_swf_url: '/plupload/js/plupload.flash.swf',
// Silverlight settings
silverlight_xap_url: '/plupload/js/plupload.silverlight.xap'
});
});
</script>
[HttpPost]
public ActionResult Upload(int? chunk, string name)
{
var fileUpload = Request.Files[0];
var uploadPath = Server.MapPath("~/App_Data");
chunk = chunk ?? 0;
using (var fs = new FileStream(Path.Combine(uploadPath, name), chunk == 0 ? FileMode.Create : FileMode.Append))
{
if (fileUpload != null)
{
var buffer = new byte[fileUpload.InputStream.Length];
fileUpload.InputStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
}
}
return Content("chunk uploaded", "text/plain");
}
public class album
{
public string name;
public string des;
public string[] images;
}uploader.bind('FileUploaded', function(up, file, info) {
var obj = JSON.parse(info.response);
$('form#quoteRequest').append('<input type="hidden" name="file_name" value="' + obj.result.cleanFileName + '" />');
//note obj.result.cleanFileName instead obj.cleanFileName
});// JS
up.settings.multipart_params = {
description: $("#imageDescription").val(),
// other fields ....
};
// C#
string description = context.Request.Form["description"];$("#uploader").pluploadQueue({
// Post init events, bound after the internal events
init: {
FileUploaded: function(up, file, info) {
// Called when a file has finished uploading
}
}
});// JS
up.settings.multipart_params = {
description: $("#imageDescription").val()
};
// C#
string description = context.Request.Form["description"];