Answers for "upload image flutter"

0

flutter image load

Image.asset(name) is essentially Image(image: AssetImage(name)),
Image.file(path) is essentially Image(image: FileImage(File(path))),
Image.network(url) is essentially Image(image: NetworkImage(url)),
Image.memory(list) is essentially Image(image: MemoryImage(list))
Posted by: Guest on February-19-2021
1

uploading image flutter

var d = "$tmpFile";
      var dd = d.split("'");
      var filename = dd[1].split('/').last;
      FormData formData = new FormData.fromMap({
        "user_id": "3225",
        "image": await MultipartFile.fromFile(dd[1], filename: "$filename"),
      });
      var response = await dio.post(
        'http://10.0.2.2/test/upload.php',
        data: formData,
        onSendProgress: (received, total) {
          if (total != -1) {
            print((received / total * 100).toStringAsFixed(0) + "%");
          }
        },
      );
      print(response);
Posted by: Guest on March-16-2021
0

dart http image upload

var postUri = Uri.parse("apiUrl");

http.MultipartRequest request = new http.MultipartRequest("POST", postUri);

http.MultipartFile multipartFile = await http.MultipartFile.fromPath(
    'file', filePath); 

request.files.add(multipartFile);

http.StreamedResponse response = await request.send();


print(response.statusCode);
Posted by: Guest on July-03-2021
0

how to upload image in flutter

import 'dart:io';
import 'package:http/http.dart' as http;
 
_asyncFileUpload(String text, File file) async{
   //create multipart request for POST or PATCH method
   var request = http.MultipartRequest("POST", Uri.parse("<url>"));
   //add text fields
   request.fields["text_field"] = text;
   //create multipart using filepath, string or bytes
   var pic = await http.MultipartFile.fromPath("file_field", file.path);
   //add multipart to request
   request.files.add(pic);
   var response = await request.send();
 
   //Get the response from the server
   var responseData = await response.stream.toBytes();
   var responseString = String.fromCharCodes(responseData);
   print(responseString);
}
Posted by: Guest on September-18-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language