Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Cancel upload and add Progress Callback befor internally save #807

Closed
3 tasks done
mbfakourii opened this issue Dec 13, 2022 · 8 comments · Fixed by #806
Closed
3 tasks done

Cancel upload and add Progress Callback befor internally save #807

mbfakourii opened this issue Dec 13, 2022 · 8 comments · Fixed by #806
Labels
type:feature New feature or improvement of existing feature

Comments

@mbfakourii
Copy link
Member

mbfakourii commented Dec 13, 2022

New Feature / Enhancement Checklist

Current Limitation

It is not possible to stop the upload.
It is also not possible to give Progress Callback file to Parse before internally saving

Feature / Enhancement Description

I suggest that this possibility exists because it is very important, especially to cancel the upload

Example Use Case

ParseFile file=...;

file.cancel("reason");

and

ParseFile file=...;

file.progressCallback((count, total) {
  print("total=$total | count=$count");
});

file.save();

Alternatives / Workarounds

Currently, these tasks are not possible

@parse-github-assistant
Copy link

parse-github-assistant bot commented Dec 13, 2022

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

@mbfakourii mbfakourii added the type:feature New feature or improvement of existing feature label Dec 13, 2022
@mtrezza
Copy link
Member

mtrezza commented Dec 14, 2022

Did you model this after other Parse SDKs, in case they support this feature yet? Because we want the method names, behavior and approaches to be similar as much as possible.

@mbfakourii
Copy link
Member Author

mbfakourii commented Dec 14, 2022

Did you model this after other Parse SDKs, in case they support this feature yet? Because we want the method names, behavior and approaches to be similar as much as possible.

for cancel upload and download, yes in Parse SDK Android and Parse SDK IOS

Regarding the second case, if we don't request a callback first, we can't good manage the upload or download progress.

@mtrezza
Copy link
Member

mtrezza commented Dec 14, 2022

Is it even possible that a file upload and download are in progress at the same time? Either a file needs to uploaded or downloaded. Maybe instead of separate file.cancelDownload("reason"); and file.cancelUpload("reason"); we can just have a generic file.cancel("reason");? That would then be the same syntax as in the other Parse SDKs.

The same for the progress callback. I see in the 2 SDKs that you mentioned, the callback is actually a handler that is passed when calling save:

Android SDK:

ParseFile file = new ParseFile("resume.txt", data);

file.saveInBackground(new SaveCallback() {
  public void done(ParseException e) {
    // Handle success or failure here ...
  }
}, new ProgressCallback() {
  public void done(Integer percentDone) {
    // Update your progress spinner here. percentDone will be between 0 and 100.
  }
});

Apple SDK:

PFFileObject *file = [PFFileObject fileObjectWithName:@"resume.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  // Handle success or failure here ...
} progressBlock:^(int percentDone) {
  // Update your progress spinner here. percentDone will be between 0 and 100.
}];

This way there is no ambiguity as the handler is part of the save method. Would a similar pattern make sense for Flutter?

@mbfakourii
Copy link
Member Author

Is it even possible that a file upload and download are in progress at the same time? Either a file needs to uploaded or downloaded. Maybe instead of separate file.cancelDownload("reason"); and file.cancelUpload("reason"); we can just have a generic file.cancel("reason");? That would then be the same syntax as in the other Parse SDKs.

The same for the progress callback. I see in the 2 SDKs that you mentioned, the callback is actually a handler that is passed when calling save:

Android SDK:

ParseFile file = new ParseFile("resume.txt", data);

file.saveInBackground(new SaveCallback() {
  public void done(ParseException e) {
    // Handle success or failure here ...
  }
}, new ProgressCallback() {
  public void done(Integer percentDone) {
    // Update your progress spinner here. percentDone will be between 0 and 100.
  }
});

Apple SDK:

PFFileObject *file = [PFFileObject fileObjectWithName:@"resume.txt" data:data];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  // Handle success or failure here ...
} progressBlock:^(int percentDone) {
  // Update your progress spinner here. percentDone will be between 0 and 100.
}];

This way there is no ambiguity as the handler is part of the save method. Would a similar pattern make sense for Flutter?

In the case of cancel, a function can be written
But in the case of addUploadProgressCallback, no, what is in the Android SDK, the upload process starts with the saveInBackground call, but with the addUploadProgressCallback function, you can start the upload with ProgressCallback at any time. This topic is used a lot in object storage, for example

ParseObject object=ParseObject("book");

ParseFile file=...;
file.addUploadProgressCallback((count, total) {
  print("total=$total | count=$count");
});

object.img = file;

object.save();

@mtrezza
Copy link
Member

mtrezza commented Dec 16, 2022

Got it, then maybe we can simplify the name at least. Would it make sense to add it as a property, so it be set like this (pseudo code)?

progressCallback(count, total) {
  print("total=$total | count=$count");
}

file.progressCallback = progressCallback;

@mbfakourii
Copy link
Member Author

mbfakourii commented Dec 16, 2022

Got it, then maybe we can simplify the name at least. Would it make sense to add it as a property, so it be set like this (pseudo code)?

progressCallback(count, total) {
  print("total=$total | count=$count");
}

file.progressCallback = progressCallback;

changed

ParseFile file=...;

file.progressCallback((count, total) {
  print("total=$total | count=$count");
});

file.save();

and now it works for both download and upload

@mtrezza
Copy link
Member

mtrezza commented Dec 16, 2022

Amazing!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants