استفاده از Flash Uploader در ASP.NET MVC
نویسنده: وحید نصیری
تاریخ: ۱۳۹۱/۱۱/۲۰ ۲۲:۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
@helper AddFlashUploader(
string uploadUrl,
string queryParameters,
string flashUrl,
int totalUploadSizeLimit = 0,
int uploadFileSizeLimit = 0,
string fileTypes = "",
string fileTypeDescription = "",
string onUploadComplete = "")
{
onUploadComplete = string.IsNullOrEmpty(onUploadComplete) ? "" : "completeFunction=" + onUploadComplete;
queryParameters = Server.UrlEncode(queryParameters);
fileTypes = string.IsNullOrEmpty(fileTypes) ? "" : "&fileTypes=" + Server.UrlEncode(fileTypes);
fileTypeDescription = string.IsNullOrEmpty(fileTypeDescription) ? "" : "&fileTypeDescription=" + Server.UrlEncode(fileTypeDescription);
var totalUploadSizeLimitData = totalUploadSizeLimit > 0 ? "&totalUploadSize=" + totalUploadSizeLimit : "";
var uploadFileSizeLimitData = uploadFileSizeLimit > 0 ? "&fileSizeLimit=" + uploadFileSizeLimit : "";
var flashVars = onUploadComplete + fileTypes + fileTypeDescription + totalUploadSizeLimitData + uploadFileSizeLimitData + "&uploadPage=" + uploadUrl + "?" + queryParameters;
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
width="575" height="375" id="fileUpload" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="@flashUrl" />
<param name="quality" value="high" />
<param name="wmode" value="transparent">
<param name=FlashVars value="@flashVars">
<embed src="@flashUrl"
FlashVars="@flashVars"
quality="high"
wmode="transparent"
width="575"
height="375"
name="fileUpload"
align="middle"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
}@{
ViewBag.Title = "Index";
var uploadUrl = Url.Action("Uploader", "Home");
var flashUrl = Url.Content("~/Content/FlashUpload/FlashFileUpload.swf");
}
<h2>
Flash Uploader</h2>
<div style="background: #E0EBEF;">
@FlashUploadHelper.AddFlashUploader(
uploadUrl: uploadUrl,
queryParameters: "User=Vahid&Id=تست",
flashUrl: flashUrl,
fileTypeDescription: "Images",
fileTypes: "*.gif; *.png; *.jpg; *.jpeg",
uploadFileSizeLimit: 0,
totalUploadSizeLimit: 0,
onUploadComplete: "alert('انجام شد');")
</div>using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Web.Mvc;
namespace MvcFlashUpload.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Uploader(string User, string Id, IEnumerable<HttpPostedFileBase> FileData)
{
var queryParameter1 = User;
var queryParameter2 = Id;
// ...
foreach (var file in FileData)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), fileName);
file.SaveAs(path);
}
}
return Content(" ");
}
}
}