@@ -93,6 +93,91 @@ export interface INotifyMessage {
9393 type : "error" | 'info' | 'success' | 'warning'
9494}
9595
96+ const MIME_TYPES : Record < string , string > = {
97+ "aac" : "audio/aac" ,
98+ "abw" : "application/x-abiword" ,
99+ "apng" : "image/apng" ,
100+ "arc" : "application/x-freearc" ,
101+ "avif" : "image/avif" ,
102+ "avi" : "video/x-msvideo" ,
103+ "azw" : "application/vnd.amazon.ebook" ,
104+ "bin" : "application/octet-stream" ,
105+ "bmp" : "image/bmp" ,
106+ "bz" : "application/x-bzip" ,
107+ "bz2" : "application/x-bzip2" ,
108+ "cda" : "application/x-cdf" ,
109+ "csh" : "application/x-csh" ,
110+ "css" : "text/css" ,
111+ "csv" : "text/csv" ,
112+ "doc" : "application/msword" ,
113+ "docx" : "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ,
114+ "eot" : "application/vnd.ms-fontobject" ,
115+ "epub" : "application/epub+zip" ,
116+ "gz" : "application/gzip" ,
117+ "gzip" : "application/gzip" ,
118+ "yml" : "application/x-yaml" ,
119+ "yaml" : "application/x-yaml" ,
120+ "gif" : "image/gif" ,
121+ "htm" : "text/html" ,
122+ "html" : "text/html" ,
123+ "ico" : "image/vnd.microsoft.icon" ,
124+ "ics" : "text/calendar" ,
125+ "jar" : "application/java-archive" ,
126+ "jpeg" : "image/jpeg" ,
127+ "jpg" : "image/jpeg" ,
128+ "js" : "text/javascript" ,
129+ "json" : "application/json" ,
130+ "jsonld" : "application/ld+json" ,
131+ "md" : "text/markdown" ,
132+ "mid" : "audio/midi" ,
133+ "midi" : "audio/midi" ,
134+ "mjs" : "text/javascript" ,
135+ "mp3" : "audio/mpeg" ,
136+ "mp4" : "video/mp4" ,
137+ "mpeg" : "video/mpeg" ,
138+ "mpkg" : "application/vnd.apple.installer+xml" ,
139+ "odp" : "application/vnd.oasis.opendocument.presentation" ,
140+ "ods" : "application/vnd.oasis.opendocument.spreadsheet" ,
141+ "odt" : "application/vnd.oasis.opendocument.text" ,
142+ "oga" : "audio/ogg" ,
143+ "ogv" : "video/ogg" ,
144+ "ogx" : "application/ogg" ,
145+ "opus" : "audio/ogg" ,
146+ "otf" : "font/otf" ,
147+ "png" : "image/png" ,
148+ "pdf" : "application/pdf" ,
149+ "php" : "application/x-httpd-php" ,
150+ "ppt" : "application/vnd.ms-powerpoint" ,
151+ "pptx" : "application/vnd.openxmlformats-officedocument.presentationml.presentation" ,
152+ "rar" : "application/vnd.rar" ,
153+ "rtf" : "application/rtf" ,
154+ "sh" : "application/x-sh" ,
155+ "svg" : "image/svg+xml" ,
156+ "tar" : "application/x-tar" ,
157+ "tif" : "image/tiff" ,
158+ "tiff" : "image/tiff" ,
159+ "ts" : "application/typescript" ,
160+ "ttf" : "font/ttf" ,
161+ "txt" : "text/plain" ,
162+ "vsd" : "application/vnd.visio" ,
163+ "wav" : "audio/wav" ,
164+ "weba" : "audio/webm" ,
165+ "webm" : "video/webm" ,
166+ "webmanifest" : "application/manifest+json" ,
167+ "webp" : "image/webp" ,
168+ "woff" : "font/woff" ,
169+ "woff2" : "font/woff2" ,
170+ "xhtml" : "application/xhtml+xml" ,
171+ "xls" : "application/vnd.ms-excel" ,
172+ "xlsx" : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ,
173+ "xml" : "application/xml" ,
174+ "xul" : "application/vnd.mozilla.xul+xml" ,
175+ "zip" : "application/zip" ,
176+ "3gp" : "video/3gpp" ,
177+ "3g2" : "video/3gpp2" ,
178+ "7z" : "application/x-7z-compressed"
179+ } ;
180+
96181interface APII {
97182 base_path : string ,
98183 proxy_path : string ,
@@ -815,7 +900,8 @@ export default function RestImport({ language, restImportConfig }: { language: s
815900 multipartParams . forEach ( ( data , index ) => {
816901 if ( data . name && data . value ) {
817902 if ( data . type === 'file' ) {
818- formDataOject . append ( data . name , new Blob ( [ data . value ] , { type : 'application/json' } ) , data . filename )
903+ //@ts -ignore
904+ formDataOject . append ( data . name , new Blob ( [ data . value ] , { type : getContentTypeFromFileName ( data . filename , data ?. value ?. type ) } ) , data . filename )
819905 multiParamInfoList . push ( { name : data . name , type : 'file' , list : true , contentType : undefined , testValue : undefined } )
820906 } else {
821907 formDataOject . append ( data . name , data . contentType === 'text' ? data . value : new Blob ( [ data . value ] , { type : data . contentType } ) )
@@ -827,6 +913,25 @@ export default function RestImport({ language, restImportConfig }: { language: s
827913 } )
828914 return formDataOject
829915 }
916+ function getContentTypeFromFileName ( filename : string | null | undefined , type : string | null | undefined ) : string {
917+ if ( type && type . trim ( ) && type . trim ( ) !== "" ) {
918+ return type ;
919+ }
920+
921+ if ( ! filename || ! filename . trim ( ) ) {
922+ return "application/octet-stream" ;
923+ }
924+
925+ const ext = filename . includes ( "." )
926+ ? filename . split ( "." ) . pop ( ) ?. toLowerCase ( )
927+ : "" ;
928+
929+ if ( ! ext || ext . trim ( ) === "" ) {
930+ return "application/octet-stream" ;
931+ }
932+
933+ return MIME_TYPES [ ext ] || "application/octet-stream" ;
934+ }
830935 let requestConfig : ICustomAxiosConfig = { }
831936 if ( useProxy ) {
832937 requestConfig = {
0 commit comments