Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

iOS upload returns 500 #160

Closed
samigimix opened this issue Apr 29, 2021 · 11 comments
Closed

iOS upload returns 500 #160

samigimix opened this issue Apr 29, 2021 · 11 comments
Assignees
Labels
bug Something isn't working ios iOS-only issues

Comments

@samigimix
Copy link

samigimix commented Apr 29, 2021

Hello!

I used the bellow function to upload .JPG and .PDF file. It works on Android and it logs the progress too, but in iOS Simulator after 2 seconds it shows the following error: (Also i used .enqueue too but get same result)

CODE:

FlutterUploader uploader = FlutterUploader();

  await uploader
      .enqueueBinary(
    url:
        "https://******.******.net/api/services/app/BlobManager/UploadMedicalCheckFile",
    file: FileItem(
      filename: file.name,
      savedDir: file.directory,
      fieldname: "File",
    ),
    method: UploadMethod.POST,
    headers: {
      "Authorization": "Bearer ${user.accessToken}",
      "content-type": "application/json",
    },
    showNotification: true,
  )
      .onError((error, stackTrace) {
    print(error);
    print(stackTrace.toString());
    return null;
  }).then((value) => print("DONE!"));

ERROR:

flutter: DONE!
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: taskId: chillisource.flutter_uploader.upload.background.4, status:UploadTaskStatus(4), statusCode:500, code:upload_error, message:{"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}}, tag:null
16 libsystem_pthread.dylib 0x00007fff61166467 start_wqthread + 15
15 libsystem_pthread.dylib 0x00007fff61167453 _pthread_wqthread + 244
14 libdispatch.dylib 0x00007fff20116871 _dispatch_worker_thread2 + 102
13 libdispatch.dylib 0x00007fff20116074 _dispatch_root_queue_drain + 350
12 libdispatch.dylib 0x00007fff201080bb _dispatch_async_redirect_invoke + 747
11 libdispatch.dylib 0x00007fff201089fb _dispatch_continuation_pop + 445
10 libdispatch.dylib 0x00007fff20106508 _dispatch_client_ca<…>

FLUTTER DOCTOR:

[✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.3 20D91 darwin-x64, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.55.2)
[✓] Connected device (2 available)

@ened ened added bug Something isn't working ios iOS-only issues labels May 28, 2021
@ened ened self-assigned this May 28, 2021
@ened
Copy link
Collaborator

ened commented May 28, 2021

@samigimix could you please try this with the latest version (3.x)

@samigimix
Copy link
Author

samigimix commented Jun 17, 2021

@ened

I checked the GitHub page and realized that I didn't implement the AppDelegate changes but also using the flutter_downloader too so here is the final app delegate:

import UIKit
import Flutter
import flutter_downloader
import flutter_uploader
 
func registerPlugins2(registry: FlutterPluginRegistry) {
    GeneratedPluginRegistrant.register(with: registry)
}

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
    SwiftFlutterUploaderPlugin.registerPlugins = registerPlugins2
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

private func registerPlugins(registry: FlutterPluginRegistry) {
    if (!registry.hasPlugin("FlutterDownloaderPlugin")) {
       FlutterDownloaderPlugin.register(with: registry.registrar(forPlugin: "FlutterDownloaderPlugin")!)
    }
}

but it shows an error for the 1.2.1 version in my Xcode:

Type 'SwiftFlutterUploaderPlugin' has no member 'registerPlugins'

and regarding your suggestion to use the latest version, I used the 3.0.0-beta.1 version and got this error after tapping on the upload button:

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: PlatformException(invalid_path, path is not set, null, null)
#0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:581
#1 MethodChannel._invokeMethod
package:flutter/…/services/platform_channel.dart:158

#2 FlutterUploader.enqueue
package:flutter_uploader/src/flutter_uploader.dart:113

#3 uploadMedicalLogFile.
package:flightlog/Configurations/network.dart:1016

#4 uploadMedicalLogFile
package:flightlog/Configurations/network.dart:1004

#5 __ListPageState.build... (package:flightlog/Pages/MedicalCheck/add-medical-check.dart)
package:flightlog/…/MedicalCheck/add-medical-check.dart:1

and here is my code for the 3.0.0-beta.1 version:

FlutterUploader uploader = FlutterUploader();
  String string = "";

      RawUpload upload = RawUpload(
        tag: file.path.replaceAll(file.name, ""),
        method: UploadMethod.POST,
        url:
            "https://******.******.net/api/services/app/BlobManager/UploadMedicalCheckFile",
        headers: {
          "Authorization": "Bearer ${user.accessToken}",
          "content-type": "application/json",
        },
      );
      await uploader.enqueue(upload);

@ened
Copy link
Collaborator

ened commented Jun 18, 2021

Looks like you are specifying the local path in RawUpload anywhere. Maybe tag should be path really?

@samigimix
Copy link
Author

@ened yes, exactly. In the 1.2.1 version the parameters are different but in the 3.0.0-beta.1 version there is just a tag parameter to define the path.

@ened
Copy link
Collaborator

ened commented Jun 18, 2021

@samigimix are you sure? There should be a path parameter.

@samigimix
Copy link
Author

@ened I restarted the IDE and finally, the path parameter appeared! So I used the path and don't have an error in uploading part of the code, but after listening for the response, it shows an error and also didn't log the uploader worker to see the upload progress. I double-checked this new code with the same version on android and everything is fine. I also tried the MultipartFormDataUpload but got the same error.

CODE:

      FlutterUploader uploader = FlutterUploader();
      String string = "";

      RawUpload upload = RawUpload(
        path: file.path,
        tag: "File",
        method: UploadMethod.POST,
        url:
            "https://******.azurewebsites.net/api/services/app/BlobManager/UploadMedicalCheckFile",
        headers: {
          "Authorization": "Bearer ${user.accessToken}",
          "content-type": "application/json",
        },
      );

      await uploader.enqueue(upload);
      await uploader.result.first.then((value) {
        string = json.decode(value.response)["result"]["azureFileName"];
      });

ERROR:

VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: FormatException: Unexpected character (at character 1)
The operation couldn’t be completed. (kCFErrorDomainCFNetwork error 303.)
^
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1404:5)
#1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1271:9)
#2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:936:22)
#3 _parseJson (dart:convert-patch/convert_patch.dart:40:10)
#4 JsonDecoder.convert (dart:convert/json.dart:506:36)
flutter: hasPermissions - true
flutter: /Users/saman/Library/Developer/CoreSimulator/Devices/BC8C887D-9A95-448C-8208-1DE6C780F4D6/data/Containers/Data/Application/4567A7E3-1407-48C7-A5C3-2B00BB5224DF/tmp/com.dfirst.logbook-Inbox/sam.JPG
#5 JsonCodec.decode (dart:convert/json.dart:157:41)
#6 uploadMedicalLogFile..
package:flightlog/Configurations/network.dart:1048
#7 _rootRunUnary (dart:async/zone.dart:1362:47)
#8 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:152:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:70<…>

As the code is working fine on android, it shouldn't be related to request or response, I think the upload doesn't happen at all but it doesn't log the upload worker to track it.

@samigimix
Copy link
Author

for another file I got this error:

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling:
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 uploadMedicalLogFile..
package:flightlog/Configurations/network.dart:1048
#2 _rootRunUnary (dart:async/zone.dart:1362:47)
#3 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#4 _FutureListener.handleValue (dart:async/future_impl.dart:152:18)
#5 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:704:45)
#6 Future._propagateToListeners (dart:async/future_impl.dart:733:32)
#7 Future._complete (dart:async/future_impl.dart:530:7)
#8 _cancelAndValue (dart:async/stream_pipe.dart:61:12)
#9 Stream.first. (dart:async/stream.dart:1219:7)
#10 _rootRunUnary (dart:async/zone.dart:1362:47)
#11 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
<…>

and for another type of file :

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.
Receiver: null
Tried calling: length
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1 _parseJson (dart:convert-patch/convert_patch.dart:39:28)
#2 JsonDecoder.convert (dart:convert/json.dart:506:36)
flutter: hasPermissions - true
#3 JsonCodec.decode (dart:convert/json.dart:157:41)
#4 uploadMedicalLogFile..
package:flightlog/Configurations/network.dart:1048
#5 _rootRunUnary (dart:async/zone.dart:1362:47)
#6 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#7 _FutureListener.handleValue (dart:async/future_impl.dart:152:18)
#8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:704:45)
#9 Future._propagateToListeners (dart:async/future_impl.dart:733:32)
#10 Future._complete (dart:async/future_impl.dart:530:7)
#11 _cancelAndValue (dart:async/stream_pipe.dart:61:12)
#12 Strea<…>

@ened
Copy link
Collaborator

ened commented Jun 20, 2021

this line seems to cause the error:

        string = json.decode(value.response)["result"]["azureFileName"];

Can you confirm value.response truly contains json? Please print it before parsing.

@samigimix
Copy link
Author

samigimix commented Jun 20, 2021

@ened Yes, you're alright. But I tested this code for android and the response was ok. But in ios the response is :

{"result":null,"targetUrl":null,"success":false,"error":{"code":0,"message":"An internal error occurred during your request!","details":null,"validationErrors":null},"unAuthorizedRequest":false,"__abp":true}

So I think the uploading process still has a problem because it seems it didn't upload completely, so the response includes an error. Also, it doesn't show upload progress like android in the console.

@ened
Copy link
Collaborator

ened commented Jun 21, 2021

OK interesting. It's a bit puzzling because we have stable integration tests running for this project which should catch this.

Would you like to contribute a new integration test which showcases the problem?

@samigimix
Copy link
Author

First of all thanks for your fast response. Unfortunately, because I didn't have such a time, I searched for an alternative, and this article helps me to do it in another way.

@samigimix samigimix changed the title iOS simulator upload returns 500 iOS upload returns 500 Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ios iOS-only issues
Projects
None yet
Development

No branches or pull requests

2 participants