DEV Community

Cover image for Uploading a File to a Server from Flutter Using a Multi-Part (form-data) POST Request

Uploading a File to a Server from Flutter Using a Multi-Part (form-data) POST Request

Carmine Zaccagnino on February 02, 2020

My Flutter book is pretty light on advanced HTTP networking topics, focusing instead on giving a more well-rounded approach that, when it comes to ...
Collapse
 
faragan profile image
Faragan

Hey, nice tutorial, but I have an issue with the http connection.
It says:

Bad state: Insecure HTTP is not allowed by platform: http://[myIP]:3000/upload

I added

android:usesCleartextTraffic="true"

to my AndroidManifest, but it does not work.

Any solutions?

Collapse
 
nhanta0408 profile image
nhanta0408

You can try this solution: flutter.dev/docs/release/breaking-...
This works for me

Collapse
 
jktnavy profile image
JKT Navy

Hey, please help me, after try 3 method, i always get this error

I/flutter (10831): │ 🐛 NoSuchMethodError: The getter 'length' was called on null.
I/flutter (10831): │ 🐛 Receiver: null
I/flutter (10831): │ 🐛 Tried calling: length

/data/user/0/com.navy.flutter_test_upload/cache/image_picker3454028650704276924.jpg

Collapse
 
m8811163008 profile image
m8811163008

Thanks, very good article
I use nodejs on windows 10 and couldn't figure it out how to send request to local server, I think it was about firewall

Collapse
 
m8811163008 profile image
m8811163008

1)Make network Private and 2)create outbound rule in windows firewall for port 3000 on my IPv4 address which deal with local IP address of development machine (my desktop)
3) navigate to with android chrome to 192.168.43.79:3000/upload and code works fine

Collapse
 
ap8900049 profile image
Agung

Hi Carmine thanks for the article. It's useful for me!

Collapse
 
karris7 profile image
karris7

Is this working on flutter web?
I get "Error: Unsupported operation: _Namespace" when trying to do File(filename).readAsBytes().asStream(),

Collapse
 
naythithtoo profile image
Nay Thit Htoo

Hi Carmine
This article is very useful for me. And then, You used node.js. I would like to use asp.net WCF service. If you have code sample with asp.net WCF service,can you share me,please?.

Collapse
 
rahulyadavhub profile image
Rahul Yadav

Very usefull.....well done!!!
How can i upload file with custom name to files?

Collapse
 
muhammadalikust profile image
MuhammadAliKust

Hi, thanks for this good article. Can you please guide me on how to upload multiple images using multipart apis?

Collapse
 
rufat_abdurahmanov_368b2a profile image
Rufat Abdurahmanov

Nice article, but why is it so terribly formatted? You really should not post text for reading in the code blocks. Reading with horizontal scrolling is a pain.

Collapse
 
ashutosh980 profile image
Ashutosh980

request.fields['key'] = 'value'; if value is in integer then how can we pass