Veoxer
Veoxer

Reputation: 442

Flutter Firebase storage upload takes too long but only on IOS

I'm working on an upload feature for my application for both android and ios and I'm using Firebase Storage for that. I'm uploading small images which sizes barely exceed 100kb. Everything works great on my android device but for some reason my ios won't work as intended. Here's the code in question :

      final snapshot = await _firebaseStorage
          .ref()
          .child("$profilePicsFolder/$fileName")
          .putFile(resImg);
      final String imgUrl = await snapshot.ref.getDownloadURL();
      await auth.updateUserProfilePicture(photoUrl: imgUrl);

The problem here is that the putFile() takes forever on ios, but on android it barely takes a couple of seconds. And I noticed that even though the execution is still waiting on the putFile() fuction for minutes, when I check Firebase storage directly I notice that the file gets uploaded almost instantly.

Not sure what I'm doing wrong here.

Upvotes: 0

Views: 1302

Answers (3)

Anthony Humphreys
Anthony Humphreys

Reputation: 135

Roopa M is a legend, I was so irritated with this issue, but I just want to show another example, of what this, with what I did.

      if (Platform.OS === "ios") {
        const fileData = await RNFS.readFile(fileUri, "base64"); // Read file as base64
        task = ref.putString(fileData, "base64"); // Use putString with base64
      } else {
        task = ref.putFile(fileUri); // Use putFile for Android
      }
    

Upvotes: 0

Roopa M
Roopa M

Reputation: 3009

Using putData() instead of putFile() in IOS applications will help to resolve these kinds of problems.

Upvotes: 8

Veoxer
Veoxer

Reputation: 442

Just as @RoopaM suggested, using putData() instead of putFile() worked like a charm. Thank you.

Upvotes: 0

Related Questions