gpt4 book ai didi

asp.net-mvc - 如何在ASP.NET MVC中使用plupload软件包?

转载 作者:行者123 更新时间:2023-12-03 11:35:07 27 4
gpt4 key购买 nike

我正在使用plupload版本1.3.0

更具体地说,我如何定义 Controller Action 以支持分块?我可以使用HttpPosteFileBase作为参数吗?

目前,我正在使用以下代码初始化插件

在HEAD标记中

<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/jquery.ui.plupload.css" )%>" />
<link type="text/css" rel="Stylesheet" media="screen" href="<%: Url.Content( "~/_assets/css/plupload/gsl.plupload.css" )%>" />
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/gears_init.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/plupload.full.min.js" )%>"></script>
<script type="text/javascript" src="<%: Url.Content( "~/_assets/js/plupload/jquery.ui.plupload.min.js" )%>"></script>

准备好文件
$("#uploader").pluploadQueue({
runtimes: 'html5,html4,gears,flash,silverlight',
url: '<%: Url.Content( "~/Document/Upload" ) %>',
max_file_size: '5mb',
chunk_size: '1mb',
unique_names: true,
filters: [
{ title: "Documenti e Immagini", extensions: "doc,docx,xls,xlsx,pdf,jpg,png" }
],
multiple_queues: false
});

最佳答案

干得好:

[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))
{
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");
}

每个块和每个上载的文件都会多次调用此方法。它将作为参数传递块大小和文件名。我不确定您是否可以将 HttpPostedFileBase用作操作参数,因为该名称不确定。

关于asp.net-mvc - 如何在ASP.NET MVC中使用plupload软件包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4444955/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com