flutter_uploader icon indicating copy to clipboard operation
flutter_uploader copied to clipboard

Multiple API requests are happening while trying to upload a file in the latest beta version of "flutter_uploader"

Open ganeshrvel opened this issue 5 years ago • 6 comments

I tried to use the package (latest beta versions) in my application. The events are emitting correctly but the package is making huge amount of network requests while the file is being uploaded.

I noticed that the package made around 92 API requests under 5 seconds!! I am attaching a redacted API request log along with the issue. Log: uploader.log

Phone: "Oneplus 6" OS: "Android 10"

code:

      final flutterUploader = FlutterUploader();

      final taskId = await FlutterUploader().enqueue(
        MultipartFormDataUpload(
          url: 'https://url.com/post',

          files: [
            FileItem(
              path: '/path/to'
              field: 'field',
            )
          ],

          method: UploadMethod.POST,

          headers: {},

          data: {},

          tag: 'tag_name',
      );

      final subscription = flutterUploader.progress.listen((progress) {
        print('============');
        log.print('progress.progress subscription', '${progress.progress}');
        log.print('progress.status subscription', '${progress.status}');
        print('============');
      });


      final result = flutterUploader.result.listen((progress) {
        print('============');
        log.print('progress.response result', '${progress.response}');
        log.print('progress.status result', '${progress.status}');
        log.print('progress.statusCode result', '${progress.statusCode}');
        print('============');
      });

Both the stable (https://github.com/fluttercommunity/flutter_uploader/issues/141) and beta versions have blockers due of which we aren't being able to use the package in out application. What do we do?

ganeshrvel avatar Jan 14 '21 17:01 ganeshrvel

@ganeshrvel thank you for reporting the bug. The .result callback is currently called too often. You can try to keep a persisted list of downloads completed and ignore them once you see the same result again in the .result.listen callback.

ened avatar Jan 14 '21 18:01 ened

@ened The issue I reported is not about stream value, it's more of huge amount of api requests happening when I use .enque method. The API call is happening multiple times, something like 92 calls per second, Which is creating that many new posts in our backend server.

ganeshrvel avatar Jan 14 '21 18:01 ganeshrvel

@ganeshrvel can you share a bit more details, like how big the file size is? I'm not sure yet how this could happen.

ened avatar Jan 15 '21 21:01 ened

i have tried upload files on multiple sizes. The same issue is happening with files of any file size.

Found a similar issue here: https://github.com/fluttercommunity/flutter_uploader/issues/144

ganeshrvel avatar Feb 06 '21 18:02 ganeshrvel

hey i found the issue. i had to call clearUploads() before every upload. The previous upload tasks were showing up in the .result.listen.

BTW, what is the difference between clearUploads() and cancelAll()?

ganeshrvel avatar Feb 07 '21 15:02 ganeshrvel

@ened I am experiencing this bug, the .result callback gets called even when the upload wasn't completed before, but the file is still uploading. I tried checking the result.status but it seems to always be UploadTaskStatus.complete, statusCode = 200. The same thing happens in the example application as well. How may I avoid this?

Edit: my bug seems to be pretty different, the upload API is only called once, and there are no problems at all if the app was already running, though if my background isolate isn't running and I enqueue an upload, the .result callback will get fired several times, and each upload with a different taskId, making it impossible to work around that.

Pato05 avatar Aug 02 '21 13:08 Pato05