-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Request falls if FormData attachment is File instance #293
Labels
bug
Something isn't working
Comments
Merged
Sorry to bother, can someone point me at the line in the next branch where this issue gets resolved? I still see createFormData(input) {
return Object.keys(input || {}).reduce((formData, key) => {
const property = input[key];
formData.append(
key,
property instanceof Blob
? property
: typeof property === "object" && property !== null
? JSON.stringify(property)
: `${property}`,
);
return formData;
}, new FormData());
} |
same issue here. If you rewrite the fetch eta it seems ok: private contentFormatters: Record<ContentType, (input: any) => any> = {
[ContentType.Json]: (input:any) => input !== null && (typeof input === "object" || typeof input === "string") ? JSON.stringify(input) : input,
[ContentType.FormData]: (input: any) =>
Object.keys(input || {}).reduce((formData, key) => {
const property = input[key];
if(Array.isArray(property)) {
property.forEach((p) => {
formData.append(key, p)
});
} else {
formData.append(
key,
property instanceof Blob
? property
: typeof property === 'object' && property !== null
? JSON.stringify(property)
: `${property}`
);
}
return formData;
}, new FormData()),
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! I got issue with file format in FormData request. Library version:
9.0.2
.Next entity is described in OpenApi format:
When I make request with file it falls because of the incorrect file format. After research I have found the trouble point in generated code,
contentFormatters
object.After
contentFormatters
code review I found out that:I'm able to resolve the instance issue on my side but It's hack.
I noticed updates in
9.2.0
lib version that Blob instance check was added. However, the request will fall again if property is File instance or if it's Blob[] or Files[].Questions
The text was updated successfully, but these errors were encountered: