Uploading File(Image/Video) To The Server Using Multipart With Http In Flutter/Dart.

http: ^0.12.2
 flutter pub get
import 'package:http/http.dart';
var request = new http.MultipartRequest(
"POST", Uri.parse('your api url here'));
request.files
.add(await http.MultipartFile.fromPath('profile_pic', imagePath.path));
request.fields['name'] = 'Rohan';
request.fields['title'] = 'My first image';
void uploadFileToServer(File imagePath) async {
var request = new http.MultipartRequest(
"POST", Uri.parse('your api url her'));
request.fields['name'] = 'Rohan';
request.fields['title'] = 'My first image';
request.files.add(await http.MultipartFile.fromPath('profile_pic', imagePath.path));
request.send().then((response) {
http.Response.fromStream(response).then((onValue) {
try {
// get your response here...
} catch (e) {
// handle exeption
}
});
});
}

--

--

--

Flutter || Android Developer Since 2018

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to console.log variable under the cursor in Visual Studio Code

What did I learn by built Rajkot AQI PWA?

First seen

Debounce in Js

Parsing JSON Arrays as Objects with Jackson

Use a Data Structure as a temporary database

Image result for data structure image

Automating Content Workflows with Gmail, Google Sheets and Google Calendar

Breakdown: Fetch() Method

Yet Another Article on Var, Let and Const Keywords.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akshay Papneja

Akshay Papneja

Flutter || Android Developer Since 2018

More from Medium

Prevent Flutter errors when using setState after dispose

Async/Await in Flutter

A simple extension for currency format on string in Dart

Dart for Back-End: Part 1