[DEV] add mulktipart management

This commit is contained in:
Edouard DUPIN 2024-03-12 23:12:41 +01:00
parent 8e913b54ad
commit db6a20fa02
2 changed files with 10 additions and 0 deletions

View File

@ -439,6 +439,9 @@ public class DataFactoryTsApi {
if (MediaType.APPLICATION_JSON.equals(elem)) { if (MediaType.APPLICATION_JSON.equals(elem)) {
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.JSON,"); builder.append("\n\t\t\t\tcontentType: HTTPMimeType.JSON,");
break; break;
} else if (MediaType.MULTIPART_FORM_DATA.equals(elem)) {
builder.append("\n\t\t\t\tcontentType: HTTPMimeType.MULTIPART,");
break;
} }
} }
} }

View File

@ -20,6 +20,7 @@ export enum HTTPMimeType {
IMAGE_PNG = 'image/png', IMAGE_PNG = 'image/png',
JSON = 'application/json', JSON = 'application/json',
OCTET_STREAM = 'application/octet-stream', OCTET_STREAM = 'application/octet-stream',
MULTIPART = 'multipart/form-data',
} }
export interface RESTConfig { export interface RESTConfig {
@ -119,6 +120,12 @@ export function RESTRequest({ restModel, restConfig, data, params, queries }: RE
let body = data; let body = data;
if (restModel.contentType === HTTPMimeType.JSON) { if (restModel.contentType === HTTPMimeType.JSON) {
body = JSON.stringify(data); body = JSON.stringify(data);
} else if (restModel.contentType === HTTPMimeType.MULTIPART) {
const formData = new FormData();
for (const name in data) {
formData.append(name, data[name]);
}
body = formData
} }
console.log(`Call ${generateUrl}`) console.log(`Call ${generateUrl}`)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {