realize upload files

This commit is contained in:
zhengyingying 2014-04-28 17:15:59 +08:00
parent 75666ffde7
commit dfcb67d80e
3 changed files with 33 additions and 28 deletions

View File

@ -417,6 +417,7 @@ public class ScriptActionController {
HttpResponse httpResponse = this.getCommunicateWithMaster()
.uploadScriptWithParamFiles(accessToken, scriptName,
runScenarioModel, paramFiles);
Logger.getLogger(ScriptActionController.class).info(httpResponse.getContent());
OperateScriptServerResponseModel operateScriptServerResponseModel = (OperateScriptServerResponseModel) MarshalHelper
.tryUnmarshal(OperateScriptServerResponseModel.class,
httpResponse.getContent());
@ -428,6 +429,7 @@ public class ScriptActionController {
return new BaseResponseModel(false,
operateScriptServerResponseModel.getFailCauseString());
} catch (JAXBException e) {
Logger.getLogger(ScriptActionController.class).info(ExceptionLog.getStackTrace(e));
return new BaseResponseModel(false,
"Failed:invalidated script file!");
}

View File

@ -17,25 +17,25 @@ $("#pluginFinish").click(function(e) {
plugin.usePluginContainerInit(container.usePluginContainer);
plugin.usePluginParamInfosContainerInit(item);
$("#myModal_Plugin").modal('hide');
$("input[type=file]").change(function(event) {
fileChange(event);
});
// $("input[type=file]").change(function(event) {
// fileChange(event);
// });
});
function fileChange(event) {
$.each(event.target.files, function(index, file) {
$.each(event.target.files, function(index, file) {
var reader = new FileReader();
reader.onload = function(event) {
object = new Object();
object.filename = file.name;
object.data = event.target.result;
files.push(object);
};
reader.readAsDataURL(file);
});
});
}
//function fileChange(event) {
// $.each(event.target.files, function(index, file) {
// $.each(event.target.files, function(index, file) {
// var reader = new FileReader();
// reader.onload = function(event) {
// object = new Object();
// object.filename = file.name;
// object.data = event.target.result;
// files.push(object);
// };
// reader.readAsDataURL(file);
// });
// });
//}
function pluginEditorInit() {
plugin.pluginListContainerInit(container.pluginListContainer);

View File

@ -151,20 +151,23 @@ function makePageList(behaviors) {
}
function submitScriptByAjax(scriptModel){
var formData=new FormData();
var filesDiv=$("input[type=file]");
for(var i=0;i<filesDiv.length;i++){
formData.append("paramFiles",filesDiv[i].files[0],filesDiv[i].files[0].name);
}
formData.append("content",JSON.stringify(scriptModel));
$.ajax({
url : "uploadEditedScipt",
type : "POST",
url : "uploadEditScript",
data : {
content : JSON.stringify(scriptModel),
paramFiles : files
},
contentType:false,
processData:false,
data : formData,
success : function(data) {
if (!data.success) {
alert(data.failedMessage);
return;
}
data = data.data;
alert("upload success");
alert(data);
window.location.replace("script.jsp");
}
});