I am uploading video using multipartentity
in chunks, to upload I am reading data from file. In the first loop I am able to read data, but in the next loop it is getting ArrayIndexOutOfBoundsException
Exception :
> java.lang.ArrayIndexOutOfBoundsException: length=1024;
> regionStart=1024; regionLength=1024
I am reading 1024 bytes in every loop.
totalSize = 441396
offset starts from 0
chunkSize = 1024
My code:
do {
currentChunkSize = totalSize - offset > chunkSize ? chunkSize : totalSize - offset;
String urlString = "http://capmem.omsoftware.co/Event/UploadVideo?" +
"callback=localJsonpCallback&" +
"filename="+ filename +"&" +
"ext="+ exten +"&" +
"totalsize="+ size +"&" +
"EventID="+ eventid +"&" +
"UserID="+ userid +"&" +
"comment="+ coment +"&" +
"VideoLength="+ videolength +
"&chunk=" + currentChunkSize;
httppost1 = new HttpPost(urlString);
byte[] currentBytes = new byte[currentChunkSize];
buf = new BufferedInputStream(new FileInputStream(file));
buf.read(currentBytes, offset, currentChunkSize);
offset += currentChunkSize;
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("videofile", new ByteArrayBody(currentBytes, "application/octet-stream", filename));
httppost1.setEntity(reqEntity);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(httppost1);
int resCode = response.getStatusLine().getStatusCode();
} while(totalSize != offset);
Getting Exception in
buf.read(currentBytes, offset, currentChunkSize);