前端部分
前端部分主要用ajax 上傳Base64字符串碼
$("#fileInput").live("change", function() {
var path = $(this).val();
var showfilename = $(this).parent().parent().prev(); //展示文件名稱的view
showfilename.show(); //顯示展示名稱
showfilename.text(this.files[0].name);
var reader = new FileReader();
reader.readAsDataURL(this.files[0]);
reader.onload = function(e) {
console.log(e.target.result)
mui.ajax(http + _data.upload2, {
data: {
file: e.target.result,
fileModuleName: "saler",
},
dataType: 'json', //服務(wù)器返回json格式數(shù)據(jù)
type: 'post', //HTTP請求類型
timeout: timeOut,
success: function(data) {
//獲取返回的上傳成功的數(shù)據(jù)
},
error: function(xhr, type, errorThrown) {
//異常處理;
}
});
};
});
后端部分
后端部分獲取Base64之后解析出來,根據(jù)不同的格式進行再構(gòu)造,并傳給前端,主要的是格式問題,故格式整合如下(圖片類型不變,變得是其他文件類型)
word doc后綴,type為msword

doc.jpg
以此類推
word后綴docx---tyoe為 vnd.openxmlformats-officedocument.wordprocessingml.document
excel后綴xls---vnd-ms-excel
excel后綴xlsx----vnd.openxmlformats-officedocument.spreadsheetml.sheet
pdf后綴 pdf----pdf
txt后綴 ---text/plain
ppt后綴----vnd.openxmlformats-officedocument.presentationml.presentation