Ask Your Question
3

What is the method of uploading multiple files with multiple keys using the http package in Flutter using FormData?

asked 2022-01-14 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-24 19:00:00 +0000

nofretete gravatar image

To upload multiple files with multiple keys using the http package in Flutter using FormData, you can follow the steps below:

  1. Import the http package:
import 'package:http/http.dart' as http;
  1. Create a FormData object:
FormData formData = FormData();
  1. Add each file to the FormData object with a unique key:
formData.files.add(MapEntry(
    "file1", await MultipartFile.fromPath("file1", filePath1)));
formData.files.add(MapEntry(
    "file2", await MultipartFile.fromPath("file2", filePath2)));
  1. Add any other key-value pairs to the FormData object as needed:
formData.fields.add(MapEntry("key1", value1));
formData.fields.add(MapEntry("key2", value2));
  1. Send the post request with the FormData object:
var response = await http.post(url, body: formData);

This should upload multiple files with multiple keys using the http package in Flutter using FormData.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-14 11:00:00 +0000

Seen: 11 times

Last updated: Jul 24 '21