其他分享
首页 > 其他分享> > webuploader文件上传

webuploader文件上传

作者:互联网

<script src="/Content/Scripts/upload/webuploader.min.js"></script>

//上传 解析调用接口
//$('#upload-btn').click(function () {
//}

// let id = $(this).closest('tr').attr('data-id');
let progress;
let uploader = WebUploader.create({
pick: {
id: '#upload-btn',//这里是前端控件的id
multiple: false
},
auto: true,  
formData: {},
swf: '/scripts/upload/Uploader.swf', 
server: 'url', // 文件接收服务端
duplicate: true,
accept: {
//title: 'Excel',
//extensions: 'xlsx', //  
//mimeTypes: 'application/vnd.ms-excel'
extensions: gConfig.upload.allowFile[0].extensions,
mimeTypes: gConfig.upload.allowFile[0].mimeTypes
},
method: 'POST',
fileSingleSizeLimit: gConfig.upload.size //限制单个上传图片的大小
});
uploader.on('uploadSuccess', function (file, response) {
var d = Utils.ajaxResult(response._raw);
if (!Utils.codeError(d)) {
return;
}
if (d.code === gConfig.resultCode.SUCCESS) {
if (progress) {
progress.set(100);
}
if (d.msg) {
Utils.successMsg(d.msg, null, function () {
$('#search-btn').trigger('click');
});
}
} else {
var msg = d.msg;
Utils.warningMsg(msg, null, null, function () {
// searchAction.search();
});
}
if (progress) {
progress.close(1000);
}
var preWbs = headControl.data('wbs');
preWbs && wbsInpControl.val(preWbs);
});
uploader.on('uploadError', function () {//出错
if (progress) {
progress.close();
}
});
uploader.on('uploadBeforeSend', function ( data, header) {
var config = { count: 150 };
if (data.size > 1024 * 1024 * 10) {
config.count = parseInt(data.size / 80000);

} else { data.size > 1024 * 1024 * 4 } {
config.count = parseInt(data.size / 4000);
}
if (config.count > 400) {
config.count = 400;
}
progress = Utils.progress(config);
});
uploader.on('startUpload', function (object, data, header) {
});
uploader.on('uploadProgress', function (file, percentage) {//上传进度
if (progress) {
progress.set(percentage, 2);
}
});
uploader.on('error', function (type) {
switch (type) {
case 'F_EXCEED_SIZE':
Utils.warningMsg(langPurchaseListUpload.msg_UploadSizeError);
break;
case 'Q_TYPE_DENIED':
Utils.warningMsg(langPurchaseListUpload.msg_UploadTypeError);
break;
default:
break;
}
return false;
});

--后端

private Response UploadFile(HttpFile file, StockInfoService stockInfoService, WaybillOrderService waybillOrderService, PoService poService)
{
string message = Resources.Common.msg_ImportFailed;
string code = ApiResponseCode.Failed.GetStringValue();

if (file !=null)
{
IWorkbook wk = WorkbookFactory.Create(file.Value);
// XSSFWorkbook wk = new XSSFWorkbook(file.Value);
var POTracking = wk.GetSheet("1");
var POTrackingLine = wk.GetSheet("2");

if (POTracking is null || POTrackingLine is null)
{
return Response.AsJson(new ApiResponseModel<string, object>
{
Code = ApiResponseCode.Failed.GetStringValue(),
Message = "模板错误"
});
}

var fileName = Path.GetFileName(file.Name);
var invalidChars = new char[] { '+', ' ', '/', '?', '%', '#', '&', '=' };
foreach (char c in invalidChars)
{
if (fileName.Contains(c))
{
return Response.AsJson(new ApiResponseModel<string, object>
{
Code = ApiResponseCode.Failed.GetStringValue(),
Message = "文件名中不能包含特殊字符"
});
}
}

var NokiaAccount = CurrentAuthenticatedUser.NokiaAccount;

//取出数据
List<POTrackingDbEntity> pOTrackinglist = new List<POTrackingDbEntity>(1);
int index = 1;
while (true)
{
var row = POTracking.GetRow(index);
//空行或订单号为空,数据读取结束
if (row == null || row.GetCell(0) == null || string.IsNullOrEmpty(row.GetCell(0).ToString().Trim())) break;

var PONo = row.GetCell(0).ToString().Trim();
var ContractNo = row.GetCell(1).ToString().Trim();
var ShipmentSet = row.GetCell(2).ToString().Trim();
// 日期 注意这里日期格式的处理。
var ContractSignDate = string.Empty;
if (row.GetCell(3).CellType == CellType.Numeric)
{
var tpContractSignDate = row.GetCell(3).NumericCellValue;
ContractSignDate = DateTime.FromOADate(tpContractSignDate).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
ContractSignDate = row.GetCell(3).ToString();
}
}

标签:function,文件,msg,webuploader,GetCell,var,progress,上传,row
来源: https://www.cnblogs.com/Insist-Y/p/15263208.html