Skip to content

Instantly share code, notes, and snippets.

@mulieriq
Last active January 4, 2021 12:59
Show Gist options
  • Save mulieriq/67e21f0a549f604141fa49f82b26bf91 to your computer and use it in GitHub Desktop.
Save mulieriq/67e21f0a549f604141fa49f82b26bf91 to your computer and use it in GitHub Desktop.
File upload to server Using dio And http
///////////////////////////////////////////////////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