Repository: parse-community/Parse-SDK-JS (JavaScript)

Issue:
Unsuccessful cancellation of Parse File
### Issue Description

I was trying to cancel an a PFile when I noticed in my network that it successfully cancelled the PFile but created another request to continue saving the file. I tried checking who called it the second time and to my surprise, it went another attempt to save the file because of [this](https://github.com/parse-community/Parse-SDK-JS/blob/0923c93aecd2ad46f4c0d03e8a838e5fa8eeafa2/src/RESTController.js#L129).

### Steps to reproduce

1. Create a ParseFile using JS SDK
2. Save it
3. Create a setTimeout to mimic interruption after 2s
4. Cancel it

### Expected Results

Cancel the file

### Actual Outcome

Cancel the first request, then shortly after created another request to continue the previous one.

### Test Case

I don't know how will I be able to reproduce this one on a test

### Environment Setup

- **Server**
  - parse-server version (Be specific! Don't say 'latest'.) : 4.2.0
  - Operating System:     Ubuntu 18.04
  - Hardware:             
  - Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost

- **JS SDK**
  - JS SDK version: 2.13.0
  - Application? (Browser, Node, React-Native, etc): Browser

### Logs/Trace

![image](https://user-images.githubusercontent.com/32805276/81147698-6d0e7680-8fad-11ea-8dce-2d15360acf0d.png)




Discussion: That's an interesting one! I assume this affects all requests to parse server since its the `RESTController`, not only Parse.File requests?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@JeromeDeLeon Hello, did you figure out how to cancel a file upload?
Because I have the same problem after canceling, the Parse tries to upload the file 4 more times (if you cancel each one).
@baradatbiu Unfortunately no and I'm not even sure if it was fix now since I haven't used this lib in a long time.
I'll reopen this as the issue still seems to be exist as indicated by @baradatbiu's comment. This as been closed by the stale bot which has since been disabled.



Fix (patch):
diff --git a/gulpfile.js b/gulpfile.js
index 6993286c0..e79632709 100644
--- a/gulpfile.js
+++ b/gulpfile.js
@@ -65,8 +65,8 @@ const FULL_HEADER = (
   ' */\n'
 );
 
-gulp.task('compile', function() {
-  return gulp.src('src/*.js')
+function compileTask(stream) {
+  return stream
     .pipe(babel({
       presets: PRESETS[BUILD],
       plugins: PLUGINS[BUILD],
@@ -76,6 +76,10 @@ gulp.task('compile', function() {
       plugins: ['minify-dead-code-elimination'],
     }))
     .pipe(gulp.dest(path.join('lib', BUILD)));
+}
+
+gulp.task('compile', function() {
+  return compileTask(gulp.src('src/*.js'));
 });
 
 gulp.task('browserify', function(cb) {
@@ -132,14 +136,15 @@ gulp.task('minify-weapp', function() {
 });
 
 gulp.task('watch', function() {
-  return watch('src/*.js', { ignoreInitial: false, verbose: true })
-    .pipe(babel({
-      presets: PRESETS[BUILD],
-      plugins: PLUGINS[BUILD],
-    }))
-    // Second pass to kill BUILD-switched code
-    .pipe(babel({
-      plugins: ['minify-dead-code-elimination'],
-    }))
-    .pipe(gulp.dest(path.join('lib', BUILD)));
+  if (BUILD === 'browser') {
+    const watcher = gulp.watch('src/*.js', { ignoreInitial: false }, gulp.series('compile', 'browserify', 'minify'));
+    watcher.on('add', function(path) {
+      console.log(`File ${path} was added`);
+    });
+    watcher.on('change', function(path) {
+      console.log(`File ${path} was changed`);
+    });
+    return watcher;
+  }
+  return compileTask(watch('src/*.js', { ignoreInitial: false, verbose: true }));
 });
diff --git a/src/ParseFile.js b/src/ParseFile.js
index 7660e9b3b..1d7ff6945 100644
--- a/src/ParseFile.js
+++ b/src/ParseFile.js
@@ -296,6 +296,7 @@ class ParseFile {
    */
   cancel() {
     if (this._requestTask && typeof this._requestTask.abort === 'function') {
+      this._requestTask._aborted = true;
       this._requestTask.abort();
     }
     this._requestTask = null;