简体   繁体   English

在JAVA中上载时发生错误“ message [java.lang.IllegalArgumentException:im == null!]”

[英]Error While Uploading in JAVA “message[java.lang.IllegalArgumentException: im == null!]”

I am trying to upload a image file and zip file. 我正在尝试上传图像文件和zip文件。 First i have started with image upload, it gave me message[java.lang.IllegalArgumentException: im == null! 首先,我开始上传图片,它给了我message[java.lang.IllegalArgumentException: im == null! Error. 错误。 But, still it uploaded the image. 但是,它仍然上传了图像。 Then i have added code to upload zip file. 然后我添加了代码以上传zip文件。 Now also i am getting same error. 现在我也收到同样的错误。 But, unlike last time, the image only getting uploaded and its size is 0 bytes. 但是,与上次不同,该图像仅被上传​​且其大小为0字节。

I am using DWR to bring the data to server, 我正在使用DWR将数据带到服务器,

DWR Script: 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);
    }
});

} }

This the CODE i am trying. 我正在尝试此代码。

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;

}

Update: Console Log 更新:控制台日志

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!]

Final Update 最终更新

I have tried to upload zip file alone itself by commenting the other parts. 我试图通过注释其他部分来单独上载zip文件。 Its get upload. 它得到上传。 But its size also zero bytes!!! 但是它的大小也为零字节!!!

Where I am going wrong???? 我要去哪里错了????

Any suggesstions!!! 任何建议!!!

You can not get the binary value of a file in an upload field. 您无法在上载字段中获取文件的二进制值。 The value of dwr.util.getValue("uploadImage"); dwr.util.getValue("uploadImage"); is either the path of the file or empty if the browser doesn't let you read the local file path. 是文件路径,如果浏览器不允许您读取本地文件路径,则为空。 So basically you are submitting text or nothing but are trying to read it as a file. 因此,基本上您只是在提交文本或不提交任何内容,而是尝试将其作为文件读取。

I once implemented an upload file in a DWR application but I used an iframe to handle the file uploading functionality. 我曾经在DWR应用程序中实现了上传文件,但是我使用iframe来处理文件上传功能。 Recent browsers (FF3.6+, Safari4+, Chrome) do support sending files with XHR but don't count on your users to be using one them. 最近的浏览器(FF3.6 +,Safari4 +,Chrome)确实支持使用XHR发送文件,但不要指望用户使用其中的一种。

You could use an library such as FileUploader to handle this for you, they even have a Java example for the server side. 您可以使用FileUploader之类的库为您处理此问题,它们甚至在服务器端都有一个Java示例。 It uses XHR if available and falls back on an iframe workaround. 如果可用,它会使用XHR并依靠iframe解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:im == null! 错误 - java.lang.IllegalArgumentException: im == null! error 错误消息:java.lang.IllegalArgumentException - Error message: java.lang.IllegalArgumentException 错误:java.lang.IllegalArgumentException - Error: java.lang.IllegalArgumentException java.lang.IllegalArgumentException:“原始”消息参数不能为null - java.lang.IllegalArgumentException: The 'original' message argument cannot be null 读取image == java.lang.IllegalArgumentException时发生异常:image == null - Exception while reading image ==java.lang.IllegalArgumentException: image == null 为什么我得到java.lang.IllegalArgumentException:XPath为null时找不到元素错误消息 - Why do I get java.lang.IllegalArgumentException: Cannot find elements when the XPath is null error message Junit 与 MockMVC - 错误 - java.lang.IllegalArgumentException:实体不能为空 - Junit with MockMVC - Error - java.lang.IllegalArgumentException: Entity must not be null 加载图像时出错 - java.lang.IllegalArgumentException: input == null - Error in loading image - java.lang.IllegalArgumentException: input == null 改造Java.lang.IllegalArgumentException host == null - Retrofit Java.lang.IllegalArgumentException host == null java.lang.illegalArgumentException:图片==空吗? - java.lang.illegalArgumentException: Image==null?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM