Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

android - Firebase storage upload progress inaccurate

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...