2
 FormData formData = FormData.fromMap({ "image": await MultipartFile.fromFile(image.path, filename: "test.${image.path.split(".").last}") }); var dio = Dio(); var res = await dio.post( "$url/users/profile/image/add", data: formData), ); 

Code above returns like this below

{success: true, profile_picture: /files/images/users/40.png} 

Which packages do i have to use when I want to upload '/files/images/users/40.png'

3
  • what does the file upload have anything to do with "How to show Image from String Url in flutter?"? you want to upload or download? what actually do you want to achieve? Commented Jan 5, 2020 at 8:47
  • @pskink I want to download image from String url from server Commented Jan 5, 2020 at 9:09
  • check flutter.dev/docs/cookbook/networking/fetch-data Commented Jan 5, 2020 at 9:53

2 Answers 2

1

For downloading an image from URL, use image_downloader package like this :

try { // Saved with this method. var imageId = await ImageDownloader.downloadImage("https://raw.githubusercontent.com/wiki/ko2ic/image_downloader/images/flutter.png"); if (imageId == null) { return; } // Below is a method of obtaining saved image information. var fileName = await ImageDownloader.findName(imageId); var path = await ImageDownloader.findPath(imageId); var size = await ImageDownloader.findByteSize(imageId); var mimeType = await ImageDownloader.findMimeType(imageId); } on PlatformException catch (error) { print(error); } 

For uploading an image to server use below code:

import 'package:path/path.dart'; import 'package:async/async.dart'; import 'dart:io'; import 'package:http/http.dart' as http; Upload(File imageFile) async { var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead())); var length = await imageFile.length(); var uri = Uri.parse(uploadURL); var request = new http.MultipartRequest("POST", uri); var multipartFile = new http.MultipartFile('file', stream, length, filename: basename(imageFile.path)); //contentType: new MediaType('image', 'png')); request.files.add(multipartFile); var response = await request.send(); print(response.statusCode); response.stream.transform(utf8.decoder).listen((value) { print(value); }); } 

You can also refer to this tutorial for learning image upload in Flutter.

For showing an image from server URL use this code :

Image.network( imageUrl, ) 

Here imageUrl can be any image URL like

https://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png

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

Comments

0

To show an an image from the internet using its URL, you can do this :

Image.network( 'https://picsum.photos/250?image=9', ) 

To learn more, click here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.