Пример #1
0
 /**
  * Upload file.
  *
  * @param fileContent File to upload.
  * @param fileName File name to upload. Name has to be spelled exactly as written here.
  * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
  * @return the {@link Call} object
  */
 public Call<ResponseBody> uploadFileAsync(
     InputStream fileContent,
     String fileName,
     final ServiceCallback<InputStream> serviceCallback) {
   if (fileContent == null) {
     serviceCallback.failure(
         new IllegalArgumentException("Parameter fileContent is required and cannot be null."));
     return null;
   }
   if (fileName == null) {
     serviceCallback.failure(
         new IllegalArgumentException("Parameter fileName is required and cannot be null."));
     return null;
   }
   Call<ResponseBody> call = service.uploadFile(fileContent, fileName);
   call.enqueue(
       new ServiceResponseCallback<InputStream>(serviceCallback) {
         @Override
         public void onResponse(Response<ResponseBody> response, Retrofit retrofit) {
           try {
             serviceCallback.success(uploadFileDelegate(response, retrofit));
           } catch (ServiceException | IOException exception) {
             serviceCallback.failure(exception);
           }
         }
       });
   return call;
 }
Пример #2
0
 /**
  * Upload file.
  *
  * @param fileContent File to upload.
  * @param fileName File name to upload. Name has to be spelled exactly as written here.
  * @throws ServiceException exception thrown from REST call
  * @throws IOException exception thrown from serialization/deserialization
  * @throws IllegalArgumentException exception thrown from invalid parameters
  * @return the InputStream object wrapped in {@link ServiceResponse} if successful.
  */
 public ServiceResponse<InputStream> uploadFile(InputStream fileContent, String fileName)
     throws ServiceException, IOException, IllegalArgumentException {
   if (fileContent == null) {
     throw new IllegalArgumentException("Parameter fileContent is required and cannot be null.");
   }
   if (fileName == null) {
     throw new IllegalArgumentException("Parameter fileName is required and cannot be null.");
   }
   Call<ResponseBody> call = service.uploadFile(fileContent, fileName);
   return uploadFileDelegate(call.execute(), null);
 }