I want to upload an image to the server, I put all settings in the request but every time i get this error
I/flutter (17478): file response code 415
I/flutter (17478): file response body {code: 0441901, message: Non supported file type application/octet-stream only support this types[ image/jpeg,image/png ]., args: {}}
the code I'm using
import 'package:dio/dio.dart' as d;
void uploadPhoto({required XFile? image}) async {
final file = File(image!.path);
final mimeType = lookupMimeType(file.path);
print('image size: ${file.lengthSync()}');
print('image type: $mimeType');
d.FormData formData =
d.FormData.fromMap({
"avatar": await d.MultipartFile.fromFile(file.path, filename: image.name)});
d.Response response =
await d.Dio().patch('$baseURL/user/file',
data: formData,
options: d.Options(
validateStatus: (_) => true,
contentType: 'multipart/form-data',
headers: <String, dynamic>{
'Authorization': 'Bearer $accessToken',
}
)
);
print('file response code ${response.statusCode}');
print('file response body ${response.data}');
}
I have tried too many things but non of them worked for me and here's one of them [https://stackoverflow.com/questions/64176638/how-to-upload-image-to-server-with-flutter][1]