Hi, anyone on this issue. Is this a bug I am facing? Regards Lokendra
On Fri, Jun 3, 2011 at 2:46 PM, Lokendra Singh <lsingh....@gmail.com> wrote: > Hi, > > The problem occurs with text Files (with the pieces of text misplaced) as > well and not just binary data. > The users of this extension, please throw some light ! > > Regards > Lokendra > > > > On Thu, Jun 2, 2011 at 4:16 PM, Lokendra Singh <lsingh....@gmail.com>wrote: > >> >> Hi, >> >> I am not able to properly upload an image file (binary) to the Restlet >> server using the Filepload extension. The uploaded images are either >> corrupt/distorted looking or they are of lesser size than original. >> I have tried using both FileItem.write(File f) method & using the >> InputStream. >> Are there any special properties/methods to be set for uploading a binary >> data ? >> >> I have been using curl to upload the image with the following command >> curl -F "upload=@img.jpg;type=image/jpg;filename=img.jpg" >> http://localhost:.... >> >> One strange behavior is that, when in the curl command, the type parameter >> is changed to image/jpeg, the uploaded image is still corrupt & distorted >> but looks differently in the picture manager than the one uploaded with >> image/jpg. >> Please help. >> >> PS: The versions of different libs used: >> restlet-2.1-SNAPSHOT >> commons-fileupload-1.2.1/1.2.2 (both tested) >> commons-io-1.3.1 >> servlet-api-2.4 >> portlet-api-1.0 >> >> Following is the code snippet. >> >> DiskFileItemFactory factory = new DiskFileItemFactory(); >> factory.setSizeThreshold(1000240); >> RestletFileUpload upload = new RestletFileUpload(factory); >> List<FileItem> items = upload.parseRequest(getRequest()) >> . >> . >> for (final Iterator<FileItem> it = items.iterator(); it.hasNext();) { >> DiskFileItem fi = (DiskFileItem) it.next(); >> // Process the items that *really* contains an uploaded >> // file and save them on disk >> if (fi.getName() != null) { >> InputStream is = fi.getInputStream(); >> final int size=1024; >> byte[] buf; >> int ByteRead,ByteWritten=0; >> BufferedOutputStream outStream = new BufferedOutputStream(new >> FileOutputStream(uploadedFile), size); >> buf = new byte[size]; >> while ((ByteRead = is.read(buf, 0, size)) != -1) { >> outStream.write(buf, 0, ByteRead); >> ByteWritten += ByteRead; >> } >> outStream.flush(); >> outStream.close(); >> is.close(); >> //fi.write(uploadedFile) >> } >> >> Regards >> Lokendra >> > > ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2758176