I'm uploading images to the server. The image is sent in an input file to my local server, I convert it into a byte array, I set the array in a model class (BasicFileAction) and then with an object of type URL I make a connection to a service in a server where I will save the image and send as a parameter the object of type BasicFileAction and it is already saved.
The problem is that when I load an image of more than 3.68MB the image does not upload and does not send me any error message, it does not enter the catch or anything similar. It seems that it thunders in
ObjectOutputStream.writeObject(objaBasicFileAction);
I tried uploading many images, and EVERY image smaller than 3.68MB does upload it; I tried with images higher than 3.81MB and no longer uploads them. Images between 3.68MB and 3.81MB I could not get, so I do not know what exactly is the size that goes up and the one, from him, not.
My Model Class:
package com.mypackage.actions;
import java.io.Serializable;
public abstract class BasicFileAction implements Serializable{
private int[] objcFileBytes;
private String scFileName;
public int[] getFileBytes(){
return objcFileBytes;
}
public void setFileBytes( int[] objaFileBytes ){
objcFileBytes = objaFileBytes;
}
public String getFileName(){
return scFileName;
}
public void setFileName(String saFileName){
scFileName = saFileName ;
}
public abstract Object execute() throws Exception;
}
This is the method that makes the request:
public Object executeService(BasicFileAction objaBasicFileAction)
throws Exception {
URL objlURLServer = null;
ObjectInputStream objlResponse = null;
Object objlObjectResult = null;
URLConnection objlURLConnection = null;
ObjectOutputStream objlRequest = null;
TunnelException exclTunnelException = null;
try {
objlURLServer = new URL((String) objcProperties.get(
FileRemoteHandler.SERVICE_NAME));
} catch (MalformedURLException e) {
throw new Exception(
"No se puede efectuar la conexion al servidor de fotografias '" +
(String) objcProperties.get(FileRemoteHandler.SERVICE_NAME) +
"' : " + e.getMessage());
}
try {
objlURLConnection = objlURLServer.openConnection();
objlURLConnection.setDoOutput(true);
objlURLConnection.setUseCaches(false);
objlURLConnection.setRequestProperty("Content-Type",
"application/octet-stream");
System.out.println("terminando1");
objlRequest = new ObjectOutputStream(new BufferedOutputStream(
objlURLConnection.getOutputStream()));
try{
objlRequest.writeObject(objaBasicFileAction); //De aquí no pasa con las imágenes mayores a 3.68MB
objlRequest.flush();
objlRequest.close();
}catch(NotSerializableException r){
System.out.println("1 "+r.getMessage());
} catch(InvalidClassException t){
System.out.println("2 "+t.getMessage());
} catch(IOException w){
System.out.println("3 "+w.getMessage());
}
// get the result input stream
objlResponse = new ObjectInputStream(new BufferedInputStream(
objlURLConnection.getInputStream()));
// read response back from the server
objlObjectResult = objlResponse.readObject();
if (objlObjectResult instanceof TunnelException) {
exclTunnelException = (TunnelException) objlObjectResult;
throw new Exception(exclTunnelException.getMessage());
}
} catch (Exception exclException) {
System.out.println("here: "+exclException.getMessage());
throw new Exception("Error al Ejecutar la Peticion : " +
exclException.getMessage());
}
return objlObjectResult;
}
Additionally I leave you information about the byte arrays of the different requests I made.
Those that were uploaded, the size of the array is in parentheses:
3.68MB (3867314)
3.19MB (3355578)
3.05MB (3204054)
Those that did not get up:
4.09MB (4293306)
4.36MB (4572533)
3.81MB (3997079)
I have reviewed the code in the image server, it is a servlet. I put a System.out.println at the beginning of the servlet to see if the servlet could be executed and I realized that I did not. It does not pass writeObject but it does not reach the servlet either.
Any ideas?
EDIT: I have updated the way I send the data. Imagining that the arrangement I sent him was too big, I split it in two. Now the BasicFileAction class has one more parameter: the second part of the array. I have programmed everything so that writeObject receives an object of type BasicFileAction, which, as I said before, has one more arrangement that is the second half of the byte array of the image. I tested the code and it works correctly in the same way with images that weigh 3.68MB or less. In the same way, it does not pass ObjectOutputStream.writeObject (objaBasicFileAction); And in the image server it does not print anything since the first line of the servlet is not executed.
With what I've done, I've noticed that the problem is the amount of information sent to the writeObject of java.io.ObjectOutputStream , even though the byte array is passed in many fixes of smaller sizes will continue to thunder.
What about writeObject? Is the information too large that you can not send it? Is there any different way to send the images?