由于项目需要上传大文件,考虑到灵活性和美观性选择了开源的swfupload上传插件,但是在做压力测试时发现了问题
用LoadRunner单独对上传做压力测试,并发10个用户没有延时,每个用户操作5次,上传完成时理论上文件夹下面应该有50个文件,但实际上只有30多个,并且每次测试丢失文件数目不定。
如果单个用户上传文件完全没有问题。
请大侠帮忙看看怎么回事,项目马上验收了,急~!!!!!
谢谢
贴一下代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="swfupload.aspx.cs" Inherits="EAPF.WebForm.swfupload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>DemoUpload</title>
<link href="<%= ResolveUrl("~/Content/css/style.css")%>" rel="stylesheet" type="text/css" />
<link href="<%= ResolveUrl("~/Content/css/upload.css")%>" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/swf/swfupload.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/swf/fileprogress.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/swf/filegroupprogress.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/swf/handlers.js")%>"></script>
<script type="text/javascript" src="<%= ResolveUrl("~/Scripts/jquery-1.4.1.min.js")%>"></script>
<script type="text/javascript">
var swfu;
window.onload = function() {
var settings = {
post_params: {
"ASPSESSID": "<%=Session.SessionID %>"
},
file_post_name: "fileData",
// upload_url: '<%= ResolveUrl("~/upload/SaveUploadFile") %><%=paramUrl %>',
file_size_limit: "200 MB",
file_types: "*.doc;*.pdf;*.rar;",
file_types_description: "doc,pdf",
file_upload_limit: 200,
file_queue_limit: 0,
custom_settings: {
progressTarget: "divprogresscontainer",
progressGroupTarget: "divprogressGroup",
//progress object
container_css: "progressobj",
fname_css: "fle ftt",
state_div_css: "statebarSmallDiv",
state_bar_css: "statebar",
percent_css: "ftt",
href_delete_css: "ftt",
//sum object
/*
页面中不应出现以"cnt_"开头声明的元素
*/
s_cnt_progress: "cnt_progress",
s_cnt_span_text: "fle",
s_cnt_progress_statebar: "cnt_progress_statebar",
s_cnt_progress_percent: "cnt_progress_percent",
s_cnt_progress_uploaded: "cnt_progress_uploaded",
s_cnt_progress_size: "cnt_progress_size"
},
debug: false,
// Button settings
button_image_url: '<%= ResolveUrl("~/Content/images/XPButtonUploadText_61x22.png")%>',
button_width: "65",
button_height: "22",
button_placeholder_id: "spanButtonPlaceHolder",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_dialog_start_handler: fileDialogStart,
file_queued_handler: fileQueued,
file_queue_error_handler: fileQueueError,
upload_start_handler: uploadStart,
upload_progress_handler: uploadProgress,
upload_error_handler: uploadError,
upload_success_handler: uploadSuccess,
upload_complete_handler: uploadComplete,
file_dialog_complete_handler: fileDialogComplete,
flash_url: '<%= ResolveUrl("~/Content/swfupload.swf")%>',
flash9_url: '<%= ResolveUrl("~/Content/swfupload_FP9.swf")%>' // Relative to this file
};
swfu = new SWFUpload(settings);
};
</script>
<script type="text/javascript">
function startUpload() {
var url = '<%= ResolveUrl("~/upload/SaveUploadFile") %>?<%=paramUrl %>';
if (document.getElementById("divZK") != null) {
url += "&nq=" + jQuery("#txt_Year").val() + jQuery("#txt_Q").val();
}
swfu.setUploadURL(url);
swfu.startUpload();
jQuery("#spanButtonPlaceHolder").attr("disable", 'true');
}
</script>
</head>
<body>
<form id="frmMain" runat="server" enctype="multipart/form-data" enableviewstate="false">
<div style="height: 7px;">
</div>
<fieldset class="fieldset">
<legend>上传稿件</legend>
<p>
<label>
选择稿件:</label><input type="text" id="txtFileName" disabled="true" style="margin-top: -10px;
width: 240px;" />
<span id="spanButtonPlaceHolder"></span>
<br />
<span class="f_left">上传格式限DOC,PDF,方正排版文件,或上述文件格式的RAR压缩文件。(限制200M)</span>
</p>
<div id="divOp" runat="server" visible="false" style="display: none;">
<p>
<label>
篇名:</label></p>
<p>
<label>
作者:</label><input name="" type="text" id="txt_auth" style="width: 300px;" /><span>(多个作者用半角分号分隔)</span></p>
</div>
<input id="btupload" value="" class="btn4" type="button" onclick="startUpload();" />
</fieldset>
<input type="hidden" id="hf_handler" />
<input type="hidden" id="txt_name" />
</form>
</body>
</html>
接受文件的cs代码
public ActionResult SaveUploadFile(string ftype, string op, string fid,string nq)
{
string msg = string.Empty;
#region 检测
if (string.IsNullOrEmpty(ftype) || string.IsNullOrEmpty(op))
{
msg = "error:参数不能为空";
}
if (!string.IsNullOrEmpty(op) && op.ToLower()!="add" && string.IsNullOrEmpty(fid))
{
msg += "error:文件ID为空";
}
#endregion
if (string.IsNullOrEmpty(msg))
{
string pykm = m_user.CurPykm;
op = op.ToLower();
FileType ft = (FileType)System.Enum.Parse(typeof(FileType), ftype);
int count = 0; //上传次数
string handler = string.Empty;
string ext = string.Empty;
HttpPostedFileBase file;
if (Request.Files!=null && Request.Files.Count>0)
{
file = Request.Files[0];
if (file != null && file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
{
string fname = file.FileName;
ext = fname.Substring(fname.LastIndexOf('.') + 1);
string fpath = string.Empty;
fpath = EAPF.Models.FileUpload.GetUploadFilePath_whole(ext, pykm, nq, count + 1);
if (file != null)
file.SaveAs(fpath);
}
}
msg = string.Format("{{handler:'{0}',ext:'{1}',fid:'{2}',upcount:'{3}',setcount:'{4}'}}", handler, ext, fid, count, GetEditUploadTimes());
}
return Content(msg);
}
项目用mvc开发,直接提交到方法里面。
通过日志发现,所有提交过来的文件都成功保存了,丢失的文件根本没有提交到该方法里面
郁闷
文件名是怎么来生成的,会不会同一时间给覆盖了。
你可以对
Request.Files
进行循环保存文件。要么你在客户端设置一下只能同时上传一个文件。
楼主这个问题你解决了吗? loadruner 对SWFUpload 的上传代码是啥样的?我这边显示文件提取失败,上传不成功
;楼主可以讲你的loadrunner 处理的代码贴出来吗?