forum 회원 extjs 4 및 JAVA의 파일 업로드에 문제가 있습니다. 내가 extjs4 및 업로드 양식 코드를 사용하고extjs로 이미지 파일 업로드 4 spring
버튼 업로드 이미지 작용을
{
xtype: 'filefield',
margin: '10 0 0 5',
width: 296,
fieldLabel: 'Image',
emptyText: 'Select Company logo...',
id: 'cmplogo',
itemId: 'cmplogo',
name: 'cmplogo',
labelWidth: 70
},
{
xtype: 'button',
margin: '10 0 0 90',
width: 89,
text: 'Upload Image',
action: 'btn-upload-img'
},
입니다 :
fileUpload: function(btn) {
var win = btn.up('window');
var form = win.down('form').getForm();
alert('VALUE IS :'+form.getValues());
if(form.isValid()){
form.submit({
url : 'company/UploadFile.action',
waitMsg: 'Uploading your file...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your file has been uploaded.');
}
});
}
},
아래에 정의 된 기능을 가진 'btn을 업로드-IMG를'내 자바 컨트롤러는 아래 기능 코드를 가짐
@RequestMapping(value = "/company/UploadFile.action")
public @ResponseBody
Map<String, ? extends Object> uploadFile(UploadItem uploadItem, BindingResult result) throws Exception {
System.out.println("QUERY TO UPLOAD FILE");
try {
if(result.hasErrors()) {
for(ObjectError error: result.getAllErrors()) {
System.err.println("Error: "+error.getCode()+" - "+error.getDefaultMessage());
}
}
else
{
MultipartFile file = uploadItem.getFileData();
String fileName = null;
InputStream inputStream = null;
OutputStream outputStream = null;
if(file.getSize() > 0) {
inputStream = file.getInputStream();
if(file.getSize() > 10000) {
System.out.println("FILE SIZE:::"+file.getSize());
}
System.out.println("SIZE ::"+file.getSize());
fileName = "E:\\images\\"+file.getOriginalFilename();
outputStream = new FileOutputStream(fileName);
System.out.println("FILE NAME AND PATH IS ::"+fileName);
System.out.println("FILENNAME ::"+file.getOriginalFilename());
int readBytes = 0;
byte[] buffer = new byte[10000];
while((readBytes = inputStream.read(buffer, 0, 10000)) !=-1) {
outputStream.write(buffer, 0, readBytes);
}
outputStream.close();
inputStream.close();
}
}
} catch (Exception e) {
return getModelMapError("Error trying to read city");
}
return null;
}
위의 코드에 무엇이 잘못되었는지 알 수 있습니다. 내 불을 지르고 콘솔
**uncaught exception: You're trying to decode an invalid JSON String: <pre>{"message":"Error trying to read city","success":false}</pre>**
나에게 내 오류가 곧 해결 얻을 시도 할 수있는 몇 가지 솔루션을 제안 해주십시오 오류가 아래에 나와 있습니다.
이 경우 해결책을 알아낼 당신이 수 있었습니까? – pacman