I am trying to do the following:
- Take a web URL for an image and upload it into firebase
- Once the image is uploaded return the firebase URL for the image
Future<String> portrait(String imageinput) async {
// Add your function code here!
final response = await http.get(Uri.parse(imageinput));
final imageBytes = response.bodyBytes;
final storageRef = FirebaseStorage.instance
.ref()
.child('images/${DateTime.now().toString()}.jpg');
final uploadTask = storageRef.putData(imageBytes);
await uploadTask;
final String imageUrl = await storageRef.getDownloadURL();
return imageUrl;
}
2
Answers
Please follow the below code , use with your requirement
First, follow
sendImage
method thenstorage method
thenchatservice
Inside the chatService method :
This is my sendImage method
After uploading a file, you can get a URL to download the file by calling the getDownloadUrl() method on the Reference:
For updated documentation please check
https://firebase.google.com/docs/storage/flutter/upload-files