Last active
March 13, 2017 12:58
-
-
Save FAQEnD/efae329cd3cd93be7fb7fdef769cad9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NetworkOperations { | |
@Override | |
public Response<ResponseBody> directUpload(File file, String fileType, String validationKey) throws IOException { | |
Logger.debug(TAG, "Type of file: " + fileType); | |
Logger.info(TAG, "Uploading of file with name: " + file.getName()); | |
FileDataRequest wrappedFileData = WrapUtils.wrapUploadFileData(file); // any additional metadata | |
MultipartBody.Part rawFile = WrapUtils.wrapFile(file, fileType); // wrap raw file into multipart body | |
Call<UploadedFileResponse> uploadCall = mService.directUpload(wrappedFileData, rawFile, validationKey); | |
Response<UploadedFileResponse> response = uploadCall.execute(); | |
// handling of response | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface SomeRetrofitService { | |
@Multipart | |
@POST("/upload?action=save") | |
Call<UploadedFileResponse> directUpload(@Part("data") FileDataRequest data, @Part MultipartBody.Part rawFile, @Query("validationkey") String validationKey); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WrapUtils { | |
private static final String MEDIA_TYPE_MULTIPART_FORM_DATA = "multipart/form-data"; | |
public static MultipartBody.Part wrapFile(File file, String fileType) { | |
RequestBody requestFile = new RequestBody(file, MediaType.parse(MEDIA_TYPE_MULTIPART_FORM_DATA)); | |
return MultipartBody.Part.createFormData(fileType, file.getName(), requestFile); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment