Hi,
I am not able to properly upload an image file (binary) to a Restlet server.
The uploaded images are either corrupt or they are of lesser size than
original.
I have tried using both FileItem.write(File f) method & using the
FileInputStream.
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 "[email protected];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:
commons-fileupload-1.2.1/1.2.2 (both tested)
commons-io-1.3.1
servlet-api-2.4
portlet-api-1.0
Regards
Lokendra
Following is the code snippet.
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(1000240);
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)