@@ -327,50 +327,16 @@ public Call<ResponseBody> uploadAsset(@NotNull String filePath, String descripti
327
327
* @return Call
328
328
*/
329
329
public Call <ResponseBody > uploadAsset (@ NotNull String filePath , String parentUid , String title , String description , String [] tags ) {
330
- RequestBody body = RequestBody .create (MediaType .parse ("multipart/form-data" ), description );
330
+ RequestBody body = RequestBody .create (Objects . requireNonNull ( MediaType .parse ("multipart/form-data" ) ), description );
331
331
MultipartBody .Part partFile = createMultipartBody (filePath , parentUid , title , description , tags );
332
332
return this .service .uploadAsset (this .headers , partFile , body , this .params );
333
333
}
334
334
335
- private String tagConvertor (String [] tags ) {
336
- StringBuilder stringBuilder = new StringBuilder ();
337
- for (int i = 0 ; i < tags .length ; i ++) {
338
- stringBuilder .append (tags [i ]);
339
- if (i < tags .length - 1 ) {
340
- stringBuilder .append (", " );
341
- }
342
- }
343
- return stringBuilder .toString ();
344
- }
345
-
346
335
347
336
private MultipartBody .Part createMultipartBody (String filePath , String parentUid , String title , String description , String [] tags ) {
348
337
MultipartBody .Builder builder = new MultipartBody .Builder ();
349
338
builder .setType (MultipartBody .FORM );
350
-
351
- if (!filePath .isEmpty ()) {
352
- File file = new File (filePath );
353
- if (file .exists ()) {
354
- RequestBody fileBody = RequestBody .create (MediaType .parse ("multipart/form-data" ), file );
355
- builder .addFormDataPart ("asset[upload]" , file .getName (), fileBody );
356
- }
357
- }
358
-
359
- // Add other parts
360
- if (parentUid != null ) {
361
- builder .addFormDataPart ("asset[parent_uid]" , parentUid );
362
- }
363
- if (title != null ) {
364
- builder .addFormDataPart ("asset[title]" , title );
365
- }
366
- if (description != null ) {
367
- builder .addFormDataPart ("asset[description]" , description );
368
- }
369
- if (tags != null ) {
370
- builder .addFormDataPart ("asset[tags]" , tagConvertor (tags ));
371
- }
372
-
373
- return builder .build ().part (0 );
339
+ return new FileUploader ().createMultipartBody (filePath , parentUid , title , description , tags );
374
340
}
375
341
376
342
@@ -403,7 +369,7 @@ private MultipartBody.Part createMultipartBody(String filePath, String parentUid
403
369
public Call <ResponseBody > replace (@ NotNull String filePath , @ NotNull String description ) {
404
370
Objects .requireNonNull (this .assetUid , "Asset Uid Can Not Be Null OR Empty" );
405
371
MultipartBody .Part assetPath = uploadFile (filePath );
406
- RequestBody body = RequestBody .create (MediaType .parse (String .valueOf (MultipartBody .FORM )), description );
372
+ RequestBody body = RequestBody .create (Objects . requireNonNull ( MediaType .parse (String .valueOf (MultipartBody .FORM ) )), description );
407
373
return this .service .replace (this .headers , this .assetUid , assetPath , body , this .params );
408
374
}
409
375
0 commit comments