2

I'm trying to copy a user profile picture from an external service onto my firebase server. So far I have:

final File file = await new File.fromUri(Uri.parse(auth.currentUser.photoUrl)).create();
final StorageReference ref = FirebaseStorage.instance.ref().child("profile_image_${auth.currentUser.uid}.jpg");
final StorageUploadTask uploadTask = ref.put(file);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;

// add user profile picture url to user object
final userReference = FirebaseDatabase.instance
    .reference()
    .child('users/' + auth.currentUser.uid);
userReference.set({'photoUrl': downloadUrl});

The very top line gives me the error: Unsupported operation: Cannot extract a file path from a https URI

What is the correct way to do this? Should this even be done client-side? (Should I just be passing this url to firebase and use a function to download it server-side?)

1 Answer 1

3

File only supports files on a file system. To load content using HTTP use the http package. See also https://flutter.io/networking/

var httpClient = createHttpClient();
var response = await httpClient.get(url); 

and then get the data from response.body, or

var response = await httpClient.readBytes(url);

to get it as binary (Uint8List)

See also https://www.dartdocs.org/documentation/http/0.11.3+14/http/Client-class.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.