if nUploadSize is a Long integer below,
nUploadSize += currentline.getBytes().length;
Is there a way to get the actual byte size and not the length of the byte? If i try this:
nUploadSize += currentline.getBytes();
It doesn't accept saying:
The operator += is undefined for the argument type(s) long, byte[]
The reason i was asking this question is because I am trying a httppost upload with a dialog that shows progression in percentage. The problem is the Progress bar never shows any progression before the upload successful toast is shown
I have the following code:
boolean m_bSuccess = true; // initiating a boolean to be used later
try
{
//upload parameters done through multipartEntity
MultipartEntity me = new MultipartEntity();
File pFp = new File(strAttachedFile);
me.addPart("videoFile", new FileBody(pFp, "video/3gpp"));
httppost.setEntity(me);
// get the total size of the file
nTotalSize = pFp.length();
//httpPst execution
HttpResponse responsePOST = client.execute(httppost);
HttpEntity resEntity = responsePOST.getEntity();
//
InputStream inputstream = resEntity.getContent();//generate stream from post resEntity
BufferedReader buffered = new BufferedReader(new InputStreamReader(inputstream));//buffer initiated to read inputstream
StringBuilder stringbuilder = new StringBuilder();
String currentline = null;
while ((currentline = buffered.readLine()) != null)
{
// adding the
stringbuilder.append(currentline + "\n");// appending every line of upload to stringbuilder
String result = stringbuilder.toString();
nUploadSize += currentline.getBytes().length;// += upload size acquires all current line bites
//convert upload size from integer to string to be read
String s = String.valueOf(nUploadSize);
Log.i("Upload lineeeeeeeeeeeeeeeeee",s);
Log.v("HTTP UPLOAD REQUEST",result);
inputstream.close();}
}
catch (Exception e) {
e.printStackTrace();
m_bSuccess = false; //mbsucess is false on catch failure
}
publishProgress();
if(m_bSuccess)
return "success";
return null;
}
protected void onProgressUpdate(Integer... progress) {
if(m_vwProgress !=null){
m_vwProgress.setProgress((int)(nUploadSize/nTotalSize));
}
}
protected void onPostExecute(String result){
super.onPostExecute(result);
if(result==null){
if(m_vwProgress !=null)
m_vwProgress.dismiss();
Toast.makeText(m_activity, "Upload Successful", Toast.LENGTH_LONG).show();
}
}
}
When upload is attempted, during my Log.i("Upload lineeeeeeeeeeeeeeeeee",s)
; It shows the highest byte size i am getting from nUploadSize += currentline.getBytes().length;
is 200. Explaining my main problem why the Progress dialog never shows percentage progression because the number is too small. That's why i was trying to see if I was actually getting the string byte size. If anybody know how to fix this, I will be grateful.