我正在使用Plupload将文件上传到一台服务器,上传过程运行良好但是当我打开文件时(例如:docx)它说它已损坏并且其中有其他数据(我认为它是来自XMLHttpRequest的)。
您可以在此链接中看到其他数据 - > http://prntscr.com/4hl5lo
我的代码:
客户端:
AJS.$("input#edit-template-file").replaceWith('<div id="container"> <a id="pickfiles" href="javascript:;">[Select files]</a> <a id="uploadfiles" href="javascript:;">[Upload files]</a> </div>');
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'), // ... or DOM Element itself
url : '[my url]',
multi_selection: false,
send_file_name: false,
chunk_size: 0,
filters : {
max_file_size : '100mb',
mime_types: [
{title : "Doc files", extensions : "docx,docm,dotx,dotm,odt,rtf"}
]
},
// Flash settings
flash_swf_url : 'Moxie.swf',
// Silverlight settings
silverlight_xap_url : 'Moxie.xap',
init: {
PostInit: function() {
document.getElementById('uploadfiles').onclick = function() {
uploader.start();
return false;
};
},
BeforeUpload: function(up, file) {
// Called right before the upload for a given file starts, can be used to cancel it if required
delete up.settings.multipart_params; //i have tried this to remove the additional data written in the file but without sucess
console.log('[BeforeUpload]', 'File: ', file);
},
UploadProgress: function(up, file) {
AJS.progressBars.update("#templateBar", file.percent);
},
FileUploaded: function(up, file, info) {
console.log(info.response);
if (info.response != '') {
AJS.$(fileFieldId).val(info.response);
AJS.$("div#container").attr( 'name', file.name );
setSubmitState(false);
}
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
}
});
uploader.init();
服务器端(java):
public Response createFile(InputStream is) throws IOException {
final String templatesPath = buildTemplatesPath();
final File templatesDir = new File(templatesPath);
if (!templatesDir.exists()) {
templatesDir.mkdir();
}
final String tmpPath = buildTMPPath();
final File tmpDir = new File(tmpPath);
if (!tmpDir.exists()) {
tmpDir.mkdir();
}
final String fileId = UUID.randomUUID().toString();
try {
writeToFile(is, buildFilePath(fileId));
} catch (Exception e) {
logger.error("Unable to write template", e);
return Response.status(500);
}
return Response.status(200);
}
private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) throws Exception {
try {
final OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
int read = 0;
final byte[] bytes = new byte[1024];
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
} catch (Exception e) {
logger.error("Unable write file", e);
throw e;
}
}
我一直在研究这个主题并找到了Plupload在xmlhttprequest(https://github.com/moxiecode/moxie/blob/master/src/flash/src/com/XMLHttpRequest.as)中编写附加标题的文件,但是我无法删除那些数据,有什么帮助吗?
答案 0 :(得分:-2)
没有任何内容被破坏,但您必须刷新img_upload.php中添加的所有href scipt和css脚本
我的意思是哪个css文件和jquery文件包含他们的路径是通过下载jquery和css文件替换,否则检查插件通过他们的在线路径替换jquery和css文件存储然后检查插件