From 9f1de2bead555ec15d90e5f5dfa6868dd054868a Mon Sep 17 00:00:00 2001 From: Sicherhaven Date: Wed, 8 Apr 2026 21:17:55 +0530 Subject: [PATCH] fix(upload): set explicit MIME type on multipart upload Without a content type header, http package defaults to application/octet-stream which the server rejects. Derive MIME from file extension using a lookup map (Dart 2 compatible). Co-Authored-By: Claude Sonnet 4.6 --- lib/core/api/api_client.dart | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 {