I am using java for my server side application and phonegap for my client side.i need to transfer huge image files when user login to my application.
I convert those image files to base64 format and put it into json object.when i send this json object to client side i am getting java out of memory error.
How to send those image files one by one in a single request since sending all files at a time causes java memory out of error.pl help me.
Here is my code:
File folderName = new File(processingFolder+"/"+f1[i].getName());
File[] folderFiles= folderName.listFiles();
for(int m=0;m<folderFiles.length;m++)
{
System.out.println("folderFiles are:"+folderFiles[m]);
String s1 = new String();
File readfile = new File(folderFiles[m].toString());
System.out.println(readfile.exists() + "!!");
FileInputStream fis = new FileInputStream(readfile);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum);
//no doubt here is 0
/*Writes len bytes from the specified byte array starting at offset
off to this byte array output stream.*/
}
}
catch (IOException ex) {
}
byte[] bytes = bos.toByteArray();
String result2 = Base64.encode( bytes );
json1.put(folderFiles[m].getName(), result2);
i found the solution for my question.
i have send all the file names to the client side in json format. by looping the files names in the client side i send request to server and get a single file for each request. then i again write that file in my client side.