applet and "error writing to server" exception

J

jmr

Hi All,

I have an applet sending binary data to a server in order to save an image.
This works fine bug for very big images, I get an IOException "error
writing to server".
I don't know exactly the max size I could transfer (it worked ok for
3.5MB).Is there a limit somewhere ? I could not find it.
Note: this is NOT an OutOfMemory Exception.

The code is:
URL url = new URL(URLSave);
URLConnection uConn = url.openConnection();
uConn.setUseCaches(false);
uConn.setDoInput(true);
uConn.setDoOutput(true);
uConn.setRequestProperty("Content-transfer-encoding","binary");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(uConn.getOutputStream());
// HERE SOME CODE TO FILL IN bos WITH IMAGE DATA
byte [] imageBytes = bos.toByteArray ();
String imageBase64 = Base64.encodeBytes (imageBytes);
String image = URLEncoder.encode (imageBase64);
System.out.println("Encoded Image size:" + image.length());
String parameters = "type=" + URLEncoder.encode(filetype) + "&data=" +
image;
out.write (parameters.getBytes());
out.flush();
out.close();

Thanks,
Jean-Michel
 
D

Dave Miller

jmr said:
Hi All,

I have an applet sending binary data to a server in order to save an image.
This works fine bug for very big images, I get an IOException "error
writing to server".
I don't know exactly the max size I could transfer (it worked ok for
3.5MB).Is there a limit somewhere ? I could not find it.
Note: this is NOT an OutOfMemory Exception.

The code is:
URL url = new URL(URLSave);
URLConnection uConn = url.openConnection();
uConn.setUseCaches(false);
uConn.setDoInput(true);
uConn.setDoOutput(true);
uConn.setRequestProperty("Content-transfer-encoding","binary");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(uConn.getOutputStream());
// HERE SOME CODE TO FILL IN bos WITH IMAGE DATA
byte [] imageBytes = bos.toByteArray ();
String imageBase64 = Base64.encodeBytes (imageBytes);
String image = URLEncoder.encode (imageBase64);
System.out.println("Encoded Image size:" + image.length());
String parameters = "type=" + URLEncoder.encode(filetype) + "&data="
+ image;
out.write (parameters.getBytes());
out.flush();
out.close();

Thanks,
Jean-Michel

Post the stack trace for help troubleshooting the above.

The below code does not have any size limitations:

DataOutputStream out = new
DataOutputStream(connection.getOutputStream());
FileInputStream fis = new FileInputStream(your_file);
while ((i = fis.read()) != -1) {
out.write(i);
}
out.flush();
out.close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top