Image uploading failed on actual device but working perfect on emulator.

36 views
Skip to first unread message

Mohd. Asif

unread,
Feb 26, 2020, 8:08:21 AM2/26/20
to flutt...@googlegroups.com
Hello Everyone,
I need to upload an image to server using rest api.
everything woking on emulator but failed on actual device.
i have tried both libraries http and dio for this. (both working as expected on emulator)
Note: i have provided necessary permissions and imports for Physical device.
1. Using Dio
Dio dio = Dio();
FormData formData = new FormData();
formData.files.add(MapEntry("image", await MultipartFile.fromFile(photo.path, filename: "billPhoto")));
formData.fields.add(MapEntry('Userid', userId));
formData.fields.add(MapEntry('shopid', shopId));
formData.fields.add(MapEntry('bills', bills));
formData.fields.add(MapEntry('shopname', shopName));
formData.fields.add(MapEntry('Qrcodeid', qrCodeId));
var response = await dio.post(ApiUrls.insertBillDetails, data:formData);
2. Using HTTP library

Uri url = Uri.parse(ApiUrls.insertBillDetails);

      var sendRequest = http.MultipartRequest("POST", url);

      sendRequest.fields['Userid'] = userId;

      sendRequest.fields['shopid'] = shopId;

      sendRequest.fields['bills'] = bills;

      sendRequest.fields['shopname'] = shopName;

      sendRequest.fields['Qrcodeid'] = qrCodeId;

      

var pic = await http.MultipartFile.fromPath("image", photo.path,

          contentType: new MediaType(

            'image',

            'jpg',

          ));


      sendRequest.files.add(pic);

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


      final finalResp = await http.Response.fromStream(response);

--
With Warm Regards,

MOHD ASIF,


Reply all
Reply to author
Forward
0 new messages