Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set content type on MultipartFile by looking up mime type? #671

Open
Yogesh070 opened this issue May 1, 2024 · 0 comments
Open

Comments

@Yogesh070
Copy link

Yogesh070 commented May 1, 2024

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:
I have defined the api as:

@post('')
Future saveProfileGreetings(
@part() File file,
@part() String link,
@SendProgress() ProgressCallback onSendProgress,
);

This works fine but I want to assign content type on MultipartFile by looking up mime type.

Expected behavior
I want to generate the api as the following where i can set content type as :

contentType: MediaType.parse(lookupMimeType(file.path)!),

@OverRide
Future saveProfileGreetings(
File file,
String link,
void Function(int, int) onSendProgress,
) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = FormData();
_data.files.add(MapEntry(
'file',
MultipartFile.fromFileSync(
file.path,
filename: file.path.split(Platform.pathSeparator).last,
contentType: MediaType.parse(lookupMimeType(file.path)!),
),
));
_data.fields.add(MapEntry(
'link',
link,
));
await _dio.fetch(_setStreamType(Options(
method: 'POST',
headers: _headers,
extra: _extra,
contentType: 'multipart/form-data',
)
.compose(
_dio.options,
'',
queryParameters: queryParameters,
data: _data,
onSendProgress: onSendProgress,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
}

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant