Add file uploads for photos and family icons
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import "dart:convert";
|
||||
import "dart:typed_data";
|
||||
import "package:http/http.dart" as http;
|
||||
import "../config/api_config.dart";
|
||||
|
||||
@@ -45,6 +46,30 @@ class ApiClient {
|
||||
return jsonDecode(response.body) as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> postMultipart(
|
||||
String path, {
|
||||
required String fieldName,
|
||||
required Uint8List bytes,
|
||||
required String filename,
|
||||
Map<String, String>? fields,
|
||||
}) async {
|
||||
final request = http.MultipartRequest("POST", _uri(path));
|
||||
if (fields != null) {
|
||||
request.fields.addAll(fields);
|
||||
}
|
||||
request.files.add(
|
||||
http.MultipartFile.fromBytes(
|
||||
fieldName,
|
||||
bytes,
|
||||
filename: filename,
|
||||
),
|
||||
);
|
||||
final streamed = await _client.send(request);
|
||||
final response = await http.Response.fromStream(streamed);
|
||||
_ensureSuccess(response);
|
||||
return jsonDecode(response.body) as Map<String, dynamic>;
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> put(
|
||||
String path,
|
||||
Map<String, dynamic> body,
|
||||
|
||||
Reference in New Issue
Block a user