Plupload 文件大小超过 10 MB 另存为 blob 文件
Plupload file size more than 10 mb saving as blob file
我正在使用 plupload 队列小部件和示例 java servlet class。我正在尝试上传文件并将其保存在另一个目录中。
每次我尝试上传大于 10mb 的 zip 文件时,它都不会另存为 zip 文件,而只是另存为 blob 文件。它需要保存为 zip 文件。
我不知道我有什么问题 code.Any 有人可以帮助我。
提前致谢。
这是我的代码:sample.jsp
$(function () {
$("#uploader").pluploadQueue({
runtimes: 'html5,html4,flash,gears,silverlight,browserplus',
url: 'http://localhost:8080/SampleJSP/Sample',
max_file_size: '600mb',
post_max_size: '600mb',
upload_max_filesize: '600mb',
chunk_size: '10mb',
unique_names: true,
urlstream_upload:true,
multipart: true,
multiple_queues: false,
filters: [
{title: "Foto's", extensions: "jpg,gif,png"},
{title: "Video's", extensions: "wmv,avi" },
{ title: "Microsoft Office", extensions: "docx,xslx" },
{ title: "Zip files", extensions: "zip" },
],
preinit: {
preinit : {
Init: function(up, info) {
log('[Init]', 'Info:', info, 'Features:', up.features);
},
UploadFile: function(up, file) {
log('[UploadFile]', file);
}
},
UploadComplete: function (up, files) {
window.setTimeout(function (form) {
// $('#uploadFinishedForm').submit();
$('.nextButton').append('<input type="submit" class="btn btn-large btn-success submit-btn" value="Transfer" />');
}, 2000)
},
Init: function (up, info) {
$('#uploader_container').removeAttr("title");
}
}
});
$('#uploadForm').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
if (uploader.files.length > 0) {
uploader.bind('StateChanged', function () {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
$('#uploadForm').submit();
}
});
uploader.start();
} else {
$('#uploadInfo').html('Zonder foto\'s valt er niets te uploaden!');
}
return false;
});
});
Servlet 代码为::SampleServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
HttpSession session=request.getSession();
Connection con=null;
if (isMultipart) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField()) {
String fileName = item.getName();
long millisec=System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
String currDate=dateFormat.format(cal.getTime());
String name="";
String Activity="";
String Compliance_date="";
fileName=fileName;
fileName=fileName.replaceAll("\s","");
String root = getServletContext().getRealPath("/");
File path = new File(root + "/Report");
File path1 = new File("C:\Users\Desktop\working\");
File file2 = new File("C:\Users\Desktop\working\");
if (!file2.exists()) {
file2.mkdir();
}
if (file2.exists()) {
File file1 = new File("C:\Users\Desktop\working\"+fileName);
if (file1.mkdir()) {
File uploadedFile = new File(file1 + "/" + fileName);
item.write(uploadedFile);
} else {
}
}
String fid="http://localhost:8080/SampleJSP/Report/"+millisec+"/"+fileName;
session.setAttribute("fileName", fileName);
session.setAttribute("fileID", fid);
File uploadedFile = new File(file2 + "/" + fileName);
File f=new File("C:\Users\test\"+fileName);
String file_path=path1+fileName;
file_path=file_path.replace("\", "/");
try
{
con = DBManager.openDBConnection();
con.setAutoCommit(false);
Statement st = (Statement) con.createStatement();
String query = "insert into uploading_file(File,UserName,filename,filepath,FileID ,Uplodated_Datetime,activity,Compliance_date)values ('"+f+"','"+name+"','"+fileName+"','"+file_path+"', '"+millisec+"','"+currDate+"','"+Activity+"','"+Compliance_date+"')";
int ack = st.executeUpdate(query);
}
catch(Exception e)
{
e.printStackTrace();
}
// out.print("sucess");
}
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
System.out.println("UN sucess uploding.....");
//out.print("Not Uploading....");
}
我在浪费了很多 time.the 问题后找到了解决方案 chunk_size。
只需注释 chunk_size 列或将 chunk_size 替换为“0mb”
//chunk_size:'10mb'
或
chunk_size: '0mb',
我正在使用 plupload 队列小部件和示例 java servlet class。我正在尝试上传文件并将其保存在另一个目录中。
每次我尝试上传大于 10mb 的 zip 文件时,它都不会另存为 zip 文件,而只是另存为 blob 文件。它需要保存为 zip 文件。
我不知道我有什么问题 code.Any 有人可以帮助我。
提前致谢。
这是我的代码:sample.jsp
$(function () {
$("#uploader").pluploadQueue({
runtimes: 'html5,html4,flash,gears,silverlight,browserplus',
url: 'http://localhost:8080/SampleJSP/Sample',
max_file_size: '600mb',
post_max_size: '600mb',
upload_max_filesize: '600mb',
chunk_size: '10mb',
unique_names: true,
urlstream_upload:true,
multipart: true,
multiple_queues: false,
filters: [
{title: "Foto's", extensions: "jpg,gif,png"},
{title: "Video's", extensions: "wmv,avi" },
{ title: "Microsoft Office", extensions: "docx,xslx" },
{ title: "Zip files", extensions: "zip" },
],
preinit: {
preinit : {
Init: function(up, info) {
log('[Init]', 'Info:', info, 'Features:', up.features);
},
UploadFile: function(up, file) {
log('[UploadFile]', file);
}
},
UploadComplete: function (up, files) {
window.setTimeout(function (form) {
// $('#uploadFinishedForm').submit();
$('.nextButton').append('<input type="submit" class="btn btn-large btn-success submit-btn" value="Transfer" />');
}, 2000)
},
Init: function (up, info) {
$('#uploader_container').removeAttr("title");
}
}
});
$('#uploadForm').submit(function (e) {
var uploader = $('#uploader').pluploadQueue();
if (uploader.files.length > 0) {
uploader.bind('StateChanged', function () {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
$('#uploadForm').submit();
}
});
uploader.start();
} else {
$('#uploadInfo').html('Zonder foto\'s valt er niets te uploaden!');
}
return false;
});
});
Servlet 代码为::SampleServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
HttpSession session=request.getSession();
Connection con=null;
if (isMultipart) {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List items = upload.parseRequest(request);
Iterator iterator = items.iterator();
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField()) {
String fileName = item.getName();
long millisec=System.currentTimeMillis();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Calendar cal = Calendar.getInstance();
String currDate=dateFormat.format(cal.getTime());
String name="";
String Activity="";
String Compliance_date="";
fileName=fileName;
fileName=fileName.replaceAll("\s","");
String root = getServletContext().getRealPath("/");
File path = new File(root + "/Report");
File path1 = new File("C:\Users\Desktop\working\");
File file2 = new File("C:\Users\Desktop\working\");
if (!file2.exists()) {
file2.mkdir();
}
if (file2.exists()) {
File file1 = new File("C:\Users\Desktop\working\"+fileName);
if (file1.mkdir()) {
File uploadedFile = new File(file1 + "/" + fileName);
item.write(uploadedFile);
} else {
}
}
String fid="http://localhost:8080/SampleJSP/Report/"+millisec+"/"+fileName;
session.setAttribute("fileName", fileName);
session.setAttribute("fileID", fid);
File uploadedFile = new File(file2 + "/" + fileName);
File f=new File("C:\Users\test\"+fileName);
String file_path=path1+fileName;
file_path=file_path.replace("\", "/");
try
{
con = DBManager.openDBConnection();
con.setAutoCommit(false);
Statement st = (Statement) con.createStatement();
String query = "insert into uploading_file(File,UserName,filename,filepath,FileID ,Uplodated_Datetime,activity,Compliance_date)values ('"+f+"','"+name+"','"+fileName+"','"+file_path+"', '"+millisec+"','"+currDate+"','"+Activity+"','"+Compliance_date+"')";
int ack = st.executeUpdate(query);
}
catch(Exception e)
{
e.printStackTrace();
}
// out.print("sucess");
}
}
} catch (FileUploadException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
else
{
System.out.println("UN sucess uploding.....");
//out.print("Not Uploading....");
}
我在浪费了很多 time.the 问题后找到了解决方案 chunk_size。
只需注释 chunk_size 列或将 chunk_size 替换为“0mb”
//chunk_size:'10mb'
或
chunk_size: '0mb',