1010import retrofit2 .Retrofit ;
1111
1212import java .io .File ;
13+ import java .io .IOException ;
14+ import java .net .URLConnection ;
1315import java .util .HashMap ;
1416import java .util .Map ;
1517
@@ -237,8 +239,8 @@ public Call<ResponseBody> subfolder(
237239 *
238240 * @param filePath
239241 * the file path
240- * @param requestBody
241- * Request body for the asset file
242+ * @param description
243+ * The description of the asset file
242244 * <ul>
243245 * <li>asset[upload] (mandatory) Select the input type as 'File'. Then, browse and select the asset file that
244246 * you want to import. Supported file types include JPG, GIF, PNG, XML, WebP, BMP, TIFF, SVG, and PSD</li>
@@ -269,8 +271,14 @@ public Call<ResponseBody> uploadAsset(@NotNull String filePath, String descripti
269271 private MultipartBody .Part uploadFile (@ NotNull String filePath ) {
270272 if (!filePath .isEmpty ()) {
271273 File file = new File (filePath );
274+ URLConnection connection = null ;
275+ try {
276+ connection = file .toURL ().openConnection ();
277+ } catch (IOException e ) {
278+ throw new RuntimeException (e );
279+ }
272280 if (file .exists ()) {
273- RequestBody body = RequestBody .create (MediaType .parse ("multipart/form-data" ), file );
281+ RequestBody body = RequestBody .create (MediaType .parse (connection . getContentType () ), file );
274282 return MultipartBody .Part .createFormData ("asset[upload]" , file .getName (), body );
275283 }
276284 }
@@ -297,11 +305,6 @@ private MultipartBody.Part uploadFile(@NotNull String filePath) {
297305 public Call <ResponseBody > replace (@ NotNull String filePath , @ NotNull String description ) {
298306 this .validate ();
299307 MultipartBody .Part assetPath = uploadFile (filePath );
300- // if (this.headers.containsKey(Util.CONTENT_TYPE)) {
301- // this.headers.remove(Util.CONTENT_TYPE);
302- // this.headers.put(Util.CONTENT_TYPE, "multipart/form-data");
303- // }
304-
305308 RequestBody body = RequestBody .create (MediaType .parse (String .valueOf (MultipartBody .FORM )), description );
306309 return this .service .replace (this .headers , this .assetUid , assetPath , body , this .params );
307310 }
0 commit comments