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

firebase_storage: StorageReference.getPath() returns different result on iOS and Android #684

Closed
kroikie opened this issue Oct 13, 2019 · 3 comments
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) platform: android Issues / PRs which are specifically for Android. plugin: storage type: bug Something isn't working

Comments

@kroikie
Copy link
Collaborator

kroikie commented Oct 13, 2019

Using: firebase_storage: "0.3.7", this code:

Future<void> uploadActivityPhoto(
  Activity activity,
  User user,
  File image,
) async {
  final String ext = extension(image.path);

  final DateTime now = new DateTime.now();

  final StorageReference ref = FirebaseStorage.instance.ref().child(
      "/users/${user.id}/activities/${activity.id}/${now.millisecondsSinceEpoch}$ext");

  final StorageUploadTask uploadTask = ref.putFile(image);

  final Uri imageURI = (await uploadTask.future).downloadUrl;
  final String storageRef = await ref.getPath();
 
  final Map<String, dynamic> imageData = <String, dynamic>{
    'url': imageUrl,
    'storage_ref': storageRef,
  };

  final CollectionReference collectionRef =
      Firestore.instance.collection('test_upload');

  collectionRef.document().setData(imageData);
}

When uploading files on iOS, "storage_ref" is set to, e.g.

users/uZpqWlrXHabOrnqez4G8pAN2wRj1/activities/eAuMbEecePA3W5Dw8TYG/1535533628952.jpg

while on Android it will prefix storage_ref with '/', so it becomes like this:

/users/uZpqWlrXHabOrnqez4G8pAN2wRj1/activities/eAuMbEecePA3W5Dw8TYG/1535533628952.jpg

@kroikie
Copy link
Collaborator Author

kroikie commented Oct 13, 2019

@bjornbjorn

The issue at flutter/flutter#21158 has been closed and moved here. Future collaboration on this issue will be done here.

@BondarenkoStas BondarenkoStas added the type: bug Something isn't working label Oct 22, 2019
@Ehesp Ehesp added impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) plugin: storage platform: android Issues / PRs which are specifically for Android. labels Apr 21, 2020
@Ehesp
Copy link
Member

Ehesp commented Apr 21, 2020

Just to confirm, ref paths should not start with a / so Android in this case is incorrect.

@Salakar
Copy link
Member

Salakar commented Apr 1, 2021

Given the age of this issue and that Storage has had a major rework since; I'm going to close this issue in favour of trying the latest release.

@Salakar Salakar closed this as completed Apr 1, 2021
@firebase firebase locked and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
impact: customer A bug with low impact (e.g. affecting only a few customers or has a workaround). (P3) platform: android Issues / PRs which are specifically for Android. plugin: storage type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants