-
-
Notifications
You must be signed in to change notification settings - Fork 419
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi! I got issue with file format in FormData request. Library version: 9.0.2.
Next entity is described in OpenApi format:
FileSegmentCreate:
type: object
required:
- files
properties:
files:
type: array
items:
type: string
format: binary// Auto generated TS interface
export interface FileSegmentCreate {
files: File[];
}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:
- it's not allowed to have multiply files in same FormData key. There is no check for array input type;
- there is no check for Blob or File instance.
// contentFormatters
[ContentType.FormData]: (input: any) =>
Object.keys(input || {}).reduce((data, key) => {
data.append(key, input[key]);
return data;
}, new FormData()),I'm able to resolve the instance issue on my side but It's hack.
// createFileSegment expects that "files" key has File[] type;
const files = segment.files.map((file) => new Blob([file])) as any;
await api.createFileSegment({ ...segment, files: files[0] });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[].
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())Questions
- is it able to add code to convert attachment to Blob if attachment has instance File?
- is it able to add check for detecting few attachments?
Hirurgo
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working