There is a problem with the onProgress function that is overrided by addOnProgressListener.
My problem is that the TaskSnapshot when I try to upload an image does not return the bytes that have been transferred. It just stays at 0. Here is a snippet of code that I have for this:
StorageReference myStorageRef = momentsStorageRef.child(momentID + ".jpeg");
UploadTask uploadTask = myStorageRef.putBytes(data, new StorageMetadata.Builder()
.setContentType("image/jpeg")
.build());
uploadTask.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
int bytesTransferred = (int) taskSnapshot.getBytesTransferred();
int totalBytes = (int) taskSnapshot.getTotalByteCount();
int progress = (100 * bytesTransferred) / totalBytes ;
Log.v(TAG, "Bytes transferred: " + taskSnapshot.getBytesTransferred());
Log.v(TAG, "TotalBytes: " + totalBytes);
Log.v(TAG, "Upload is: " + progress + "% done");
mBuilder.setProgress(100, progress, false);
mNotifyManager.notify(APPLICATION_NOTIFICATION_ID, mBuilder.build());
}
})
Here is the logCat:
05-28 19:21:33.911 27673-27673: Bytes transferred: 0
05-28 19:21:33.911 27673-27673: TotalBytes: 205846
05-28 19:21:33.911 27673-27673: Upload is: 0% done
05-28 19:21:35.637 27673-27673: Bytes transferred: 0
05-28 19:21:35.637 27673-27673: TotalBytes: 205846
05-28 19:21:35.637 27673-27673: Upload is: 0% done
05-28 19:21:41.458 27673-27673 Bytes transferred: 205846
05-28 19:21:41.458 27673-27673 TotalBytes: 205846
05-28 19:21:41.458 27673-27673: Upload is: 100% done
firebaser here
The progress is measured in chunks of 256KB. Since your file is smaller than that, it fits in one chunk and progress thus jumps from 0% to 100% in one go.
We have an open task to improve the granularity of the progress measurement in the case of smaller files and lower bandwidth connections.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With