users@jersey.java.net

[Jersey] Re: how to upload large file more then 2 gb using jersey?

From: Vipin.nemade <nemade.vipin_at_gmail.com>
Date: Tue, 14 Feb 2012 22:02:45 -0800 (PST)

Hi Pavel,

I am using jersey multipart jar to upload a file.my server is crashing when
file 2gb or more then 2gb.

my code of rest webservice:-



@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam('file')InputStream
uploadedInputStream,_at_FormDataParam('file') FormDataContentDisposition
fileDetail,_at_HeaderParam("Content-Length") int length) {
                
println("Content-Lenght:"+""+length)

                       if(uploadedInputStream != null)
                        println("contain stream")
                
                        if(fileDetail != null)
                        println("contain file :"+fileDetail.getFileName())
                        String name = getFileName(fileDetail.getFileName())
                        println("File Name is:"+" "+name)
                        String uploadedFileLocation = "D://uploaded/"+name;
                        
                        
                        writeToFile(uploadedInputStream,uploadedFileLocation);
                        println("Test3")
                        String output = "File uploaded to : " + uploadedFileLocation;
                        return Response.status(200).entity("uploadFile size"+" "+length+"bytes"+"
"+"Uploaded file name : " +name).build();
         

        }

        // save uploaded file to new location
        private void writeToFile(InputStream uploadedInputStream,String
uploadedFileLocation) {
 
                try {
                        OutputStream out = new FileOutputStream(new File(uploadedFileLocation));
                        int read = 0;
                        byte[] bytes = new byte[1024];
 
                        out = new FileOutputStream(new File(uploadedFileLocation));
                        while ((read = uploadedInputStream.read(bytes)) != -1) {
                                out.write(bytes,0,read);
                        }
                        out.flush();
                        out.close();
                } catch (IOException e) {
 
                        e.printStackTrace();
                }

        }
Please help me to achive more then 2 gb file.

--
View this message in context: http://jersey.576304.n2.nabble.com/how-to-upload-large-file-more-then-2-gb-using-jersey-tp7283481p7286671.html
Sent from the Jersey mailing list archive at Nabble.com.