Skip to content

Instantly share code, notes, and snippets.

@Abdullamhd
Last active September 30, 2019 19:04
Show Gist options
  • Save Abdullamhd/8f564bd35ba3c0f67c4c1b4fa43a4cdb to your computer and use it in GitHub Desktop.
Save Abdullamhd/8f564bd35ba3c0f67c4c1b4fa43a4cdb to your computer and use it in GitHub Desktop.
multiple file upload using dart programming language
import 'package:http/http.dart' as http;
import 'dart:io';
import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart';
void main() async {
var uri = Uri.parse('http://localhost:3000/');
var request = http.MultipartRequest('POST', uri ,);
var path = File('b1.jpeg').path ;
print(lookupMimeType(path));
List<http.MultipartFile> files = [];
/// add files for download
files.add(await http.MultipartFile.fromPath('file', path , contentType: MediaType.parse(lookupMimeType(path))));
files.add(await http.MultipartFile.fromPath('file', path , contentType: MediaType.parse(lookupMimeType(path))));
files.add(await http.MultipartFile.fromPath('file', path , contentType: MediaType.parse(lookupMimeType(path))));
files.add(await http.MultipartFile.fromPath('file', path , contentType: MediaType.parse(lookupMimeType(path))));
/// add optional field key value pairs
files.add(http.MultipartFile.fromString('api_key', 'api_value'));
files.add(http.MultipartFile.fromString('token_key', 'token_value'));
files.add(http.MultipartFile.fromString('some_key', 'some_value'));
request.files.addAll(files);
var response = await request.send();
print(response.statusCode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment