我正在尝试上传图像文件和 zip 文件。首先我开始上传图片,它给了我message[java.lang.IllegalArgumentException: im == null!
错误。但是,它仍然上传了图像。然后我添加了代码来上传 zip 文件。现在我也遇到了同样的错误。但是,与上次不同的是,图像只是被上传并且它的大小是 0 字节。
我正在使用 DWR 将数据带到服务器,
DWR 脚本:
function uploadImage(){
var image = dwr.util.getValue("uploadImage");
var file = dwr.util.getValue("uploadFile");
dwr.util.setValue("uploadImage", null);
dwr.util.setValue("uploadFile", null);
DataUpload.uploadData(image, file, function(data){
if(data != null){
$("#imgURL").html("<p>Upload Completed!!!</p>");
$("#imgURL").append("Location: "+data.path1);
$("#zipURL").html("<p>Upload Completed!!!</p>");
$("#zipURL").append("Location: "+data.path2);
}
});
}
这是我正在尝试的代码。
public class DataUpload {
private static String DATA_STORE_LOC = "D:/Uploaded/Trials/";
public Path uploadData(InputStream image, InputStream file) throws IOException{
Path path = new Path();
BufferedImage img = ImageIO.read(image);
Date date = new Date();
DateFormat format = new SimpleDateFormat("ss");
String dat = format.format(date);
System.out.println(dat);
try {
path.setPath1(DATA_STORE_LOC+dat+".jpg");
System.out.println(DATA_STORE_LOC+dat+".jpg");
ImageIO.write(img, "jpeg", new File(DATA_STORE_LOC+dat+".jpg"));
System.out.println(true);
byte[] buffer = new byte[1024];
int len;
File f2 = new File(DATA_STORE_LOC+dat+".zip");
path.setPath2(DATA_STORE_LOC+dat+".zip");
OutputStream out = new FileOutputStream(f2);
while((len = file.read(buffer)) > 0){
out.write(buffer, 0, len);
}
file.close();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return path;
}
更新:控制台日志
49 //System.out.println(dat);
D:/Uploaded/Trials/49.jpg //System.out.println(DATA_STORE_LOC+dat+".jpg");
745859 [18820833@qtp-7494106-7] WARN org.directwebremoting.dwrp.BaseCallMarshaller - --Erroring: batchId[1] message[java.lang.IllegalArgumentException: im == null!]
最终更新
我试图通过评论其他部分来单独上传 zip 文件。它得到上传。但它的大小也是零字节!!!
我哪里错了???
任何建议!!!