uploadMultiPartFormData abstract method
Uploads data using multipart/form-data to the specified endpoint.
This method is designed to handle file uploads along with regular payload parameters. It supports adding custom headers and selecting the HTTP method type.
Parameters:
endPoint
: The API endpoint where the data will be uploaded.payloadParams
: A map containing key-value pairs of the data to be sent as part of the form (excluding file data).fileUploads
: A map containing key-value pairs where the key is the field name and the value is the file data (e.g.,File
,Uint8List
). Can benull
if no files are to be uploaded.headers
: A map of headers to include in the request (e.g., authorization tokens, content-type).method
: The HTTP method to be used for the request (e.g.,POST
,PUT
). This is defined by the IDSMethodType enum.
Returns:
- A
Future
that resolves to aMap<String, dynamic>
representing the server's response.
Example:
final response = await uploadMultiPartFormData(
endPoint: 'https://api.example.com/upload',
payloadParams: {'name': 'Test', 'description': 'File upload'},
fileUploads: {'file': ['path/to/file.png']},
headers: {'Authorization': 'Bearer your_token_here'},
method: IDSMethodType.POST,
);
print(response);
Implementation
Future<Map<String, dynamic>> uploadMultiPartFormData({
required String endPoint,
required Map<String, dynamic> payloadParams,
required Map<String, dynamic>? fileUploads,
required Map<String, dynamic> headers,
required IDSMethodType method,
});