Last active
January 4, 2021 12:59
-
-
Save mulieriq/67e21f0a549f604141fa49f82b26bf91 to your computer and use it in GitHub Desktop.
File upload to server Using dio And http
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////DIO////////////////////////////////////// | |
////////////////HEADERs | |
dio.options.headers = {'Content-Type': 'application/x-www-form-urlencoded'}; | |
//code | |
File _image; | |
String fileName = | |
_image.path.split('/').last; | |
FormData formData = | |
new FormData.fromMap({ | |
'image': await MultipartFile | |
.fromFile( | |
_image.path, | |
filename: fileName, | |
) | |
}); | |
var results = await provider | |
.upload(formData); | |
////////////////////////////////////////////////////HTTP | |
Future<String> uploadImageHTTP(file, url) async { | |
var request = http.MultipartRequest('POST', Uri.parse(url)); | |
request.files.add(await http.MultipartFile.fromPath('picture', file.path)); | |
var res = await request.send(); | |
return res.reasonPhrase; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment