开发者

image upload problem with ie7

开发者 https://www.devze.com 2023-03-17 09:02 出处:网络
i am uploading image from a simple html form <form action=\"../OctetStreamReader\" method=\"post\"accept=\"image/gif, image/jpeg\">

i am uploading image from a simple html form

 <form action="../OctetStreamReader" method="post"  accept="image/gif, image/jpeg">
 Your image: <input type="file" name="pic" id="pic" /><br />
 <input type="submit" value="Submit" />
 </form>

and inside OctetStreamReader i am copying the image on server using IOUtils

realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH) + "/";
    PrintWriter writer = 开发者_开发知识库null;
    InputStream is = null;
    FileOutputStream fos = null;

    try {
        writer = response.getWriter();
    } catch (IOException ex) {
        log(OctetStreamReader.class.getName() + "has thrown an exception: "
                + ex.getMessage());
    }

    if (canInsert) {
        // String filename = request.getHeader("X-File-Name");
        String filename = utils.createFileName(ssn, userEmail, userId);
        try {
            ImageCompressor ic= new ImageCompressor();

            is = request.getInputStream();
            fos = new FileOutputStream(new File(realPath + filename));
            logger.info("avalible bytes :" + is.available());
            IOUtils.copy(is, fos);
            logger.info("inserting copied");

the code is working absolutely fine in all browsers except IE and especially IE7. In case of IE7 , a new file is created on the server but with file size 0kb. and In case of other browsers like chrome,FF,safari , new file is created with the actual size of uploaded image. i am unable to trace out the problem as the code is not throwing any exception.

Please Help ..

Thanks !


You should add the enctype="multipart/form-data" attribute to your form element.


i tried using Apache Commons File Upload and it worked perfectly

0

精彩评论

暂无评论...
验证码 换一张
取 消