diff --git a/lib/core/api/api_client.dart b/lib/core/api/api_client.dart index 3a56fef..d7ae792 100644 --- a/lib/core/api/api_client.dart +++ b/lib/core/api/api_client.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; +import 'package:http_parser/http_parser.dart'; import '../storage/token_storage.dart'; class ApiClient { @@ -105,7 +106,21 @@ class ApiClient { /// `{ fileId, url, name, type, mimeType, size, backend }` Future> uploadFile(String url, String filePath) async { final request = http.MultipartRequest('POST', Uri.parse(url)); - request.files.add(await http.MultipartFile.fromPath('file', filePath)); + const _mimeMap = >{ + 'jpg': ['image', 'jpeg'], + 'jpeg': ['image', 'jpeg'], + 'png': ['image', 'png'], + 'webp': ['image', 'webp'], + 'mp4': ['video', 'mp4'], + 'mov': ['video', 'quicktime'], + }; + final ext = filePath.split('.').last.toLowerCase(); + final parts = _mimeMap[ext] ?? ['image', 'jpeg']; + request.files.add(await http.MultipartFile.fromPath( + 'file', + filePath, + contentType: MediaType(parts[0], parts[1]), + )); late http.StreamedResponse streamed; try {