Skip to content

Commit

Permalink
refactor(storage): progress is now a percentage between 0 and 1
Browse files Browse the repository at this point in the history
  • Loading branch information
robingenz committed Oct 19, 2023
1 parent 5c720b5 commit 086aa0d
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ Upload a file.

| Prop | Type | Description | Since |
| ---------------------- | -------------------- | ----------------------------------------------------------------------------------- | ----- |
| **`progress`** | <code>number</code> | The upload progress, as a percentage from 0 to 100. | 5.3.0 |
| **`progress`** | <code>number</code> | The upload progress, as a percentage between 0 and 1. | 5.3.0 |
| **`bytesTransferred`** | <code>number</code> | The number of bytes that have been transferred. Only available for Android and Web. | 5.3.0 |
| **`totalBytes`** | <code>number</code> | The total number of bytes to be transferred. Only available for Android and Web. | 5.3.0 |
| **`completed`** | <code>boolean</code> | Whether the upload is completed or not. | 5.3.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public UploadFileCallbackEvent(UploadTask.TaskSnapshot taskSnapshot, UploadFileS

public JSObject toJSObject() {
JSObject result = new JSObject();
result.put("progress", (100 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount());
result.put("progress", taskSnapshot.getBytesTransferred() / taskSnapshot.getTotalByteCount());
result.put("bytesTransferred", taskSnapshot.getBytesTransferred());
result.put("totalBytes", taskSnapshot.getTotalByteCount());
result.put("completed", state == UploadFileState.SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import FirebaseStorage

public func toJSObject() -> AnyObject {
var result = JSObject()
result["progress"] = 100.0 * Double(snapshot.progress!.completedUnitCount)
result["progress"] = Double(snapshot.progress!.completedUnitCount)
/ Double(snapshot.progress!.totalUnitCount)
result["completed"] = snapshot.status == .success ? true : false
return result as AnyObject
Expand Down
5 changes: 3 additions & 2 deletions packages/storage/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ export type UploadFileCallback = (
*/
export interface UploadFileCallbackEvent {
/**
* The upload progress, as a percentage from 0 to 100.
* The upload progress, as a percentage between 0 and 1.
*
* @since 5.3.0
* @example 50
* @example 0.5
*/
progress: number;
/**
Expand All @@ -364,6 +364,7 @@ export interface UploadFileCallbackEvent {
* Whether the upload is completed or not.
*
* @since 5.3.0
* @example true
*/
completed: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/storage/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class FirebaseStorageWeb
snapshot: UploadTaskSnapshot,
): UploadFileCallbackEvent {
const result: UploadFileCallbackEvent = {
progress: (snapshot.bytesTransferred / snapshot.totalBytes) * 100,
progress: snapshot.bytesTransferred / snapshot.totalBytes,
bytesTransferred: snapshot.bytesTransferred,
totalBytes: snapshot.totalBytes,
completed: snapshot.state === 'success',
Expand Down

0 comments on commit 086aa0d

Please sign in to comment.