示例#1
0
 /** Operation Execution Methods Sync * */
 public <T> T execute(String operationId, OperationBody body) {
   Object input = body.getInput();
   if (input instanceof Blob) { // If input is blob or blobs -> use multipart
     List<MultipartBody.Part> filePart = new ArrayList<>();
     RequestBody fbody =
         RequestBody.create(
             MediaType.parse(((Blob) input).getMimeType()), ((Blob) input).getFile());
     filePart.add(
         MultipartBody.Part.createFormData(INPUT_PART, ((Blob) input).getFileName(), fbody));
     return (T) getResponse(operationId, body, filePart);
   } else if (input instanceof Blobs) { // If input is blob or blobs -> use multipart
     List<MultipartBody.Part> fileParts = new ArrayList<>();
     for (int i = 0; i < ((Blobs) input).size(); i++) {
       Blob fileBlob = ((Blobs) input).getBlobs().get(i);
       RequestBody fbody =
           RequestBody.create(MediaType.parse(fileBlob.getMimeType()), fileBlob.getFile());
       fileParts.add(
           MultipartBody.Part.createFormData(
               INPUT_PARTS + String.valueOf(i), fileBlob.getFileName(), fbody));
     }
     return (T) getResponse(operationId, body, fileParts);
   } else {
     return (T) getResponse(operationId, body);
   }
 }
  public Observable<ApiResponse> uploadImage(long wmId, Uri uri) {
    File file = new File(uri.getPath());
    RequestBody fbody = RequestBody.create(MediaType.parse("application/octet-stream"), file);

    MultipartBody.Part part = MultipartBody.Part.createFormData("photo", file.getName(), fbody);
    return apiService.uploadImage(wmId, part).compose(ApiUtils.<ApiResponse>failRequestAsError());
  }