我想使用这个jQuery文件上传与我的网站https://github.com/blueimp/jQuery-File-Upload和根据文档,我需要创建我自己的文件上传处理程序,我想知道是否有人有使用jQuery文件上传在一个网站的经验?
而且,我找不到我需要创建自己的文件上传处理程序的信息。如果有人能帮忙的话,那就太好了。
我可以帮助你,我为我创建的网站创建了一个文件(图像)上传器。
CSHTML Part (subbe_archivos . CSHTML):
@{
if (IsPost)
{
var fileName = Path.GetFileName(Request.Files["archivo"].FileName);
var fileSavePath = Server.MapPath("~/Temp/" + fileName);
try
{
Request.Files["archivo"].SaveAs(fileSavePath);
<img src="~/Temp/@fileName" /> @*you could comment this line...it was the succesful response...an image preview*@
}
catch (Exception)
{
<text>Error en la subida del archivo</text> @*you could comment this line...error in the uploading*@
}
}
}
JQUERY和JAVASCRIPT部分:
function sube(archivo) {
var primer_archivo = archivo.files[0];
var data = new FormData();
data.append('archivo', primer_archivo);
$.ajax({
url: "@Href("../../operaciones/sube_archivos.cshtml")",
type: "POST",
contentType: false,
data: data,
processData: false,
cache: false,
success: function (response) {
//here I put the response ....the image preview or the error message
$(archivo).parent().next('.imagen_cargada').html(response);
//here I get the file name and I add it to some specific div
$(archivo).parent().next().next('.nombre_imagen').val($(archivo).val().split('\').pop());
}
});
}
HTML部分: <form method="post" enctype="multipart/form-data">
<input type="file" name="archivo" onchange="sube(this)" />
</form>
祝你好运,有不清楚的地方告诉我。
Blueimp是一个痛苦的插件......我建议你使用这个插件的形式和文件上传。它配置起来更简单,而且非常灵活。blueimp的问题不仅仅是让插件准备好使用。在asp.net mvc和asp.net webmatrix的服务器端也是痛苦的。