Guest User

Untitled

a guest
Jan 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. File origFile = new File(PathHolder);
  2. String getDirPath = origFile.getParent();
  3. RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), getDirPath);
  4. multipartBody = MultipartBody.Part.createFormData("uploadFiles",origFile.getName(),requestFile);
  5.  
  6. new UploadFileAsyncTask().execute();
  7.  
  8. protected notificationVO doInBackground(Void... params) {
  9. notificationVO res;
  10. WebserviceImpl webservices = new WebserviceImpl();
  11. res = webservices.notifyAttachment(token,multipartBody, getContext());
  12.  
  13. Log.e("File","browse uploaded");
  14. return res;
  15. }
  16.  
  17. @Multipart
  18. @POST("upload")
  19. public Call<notificationVO>notifyAttachment(@Query("token")String token,
  20. @Part MultipartBody.Part attachFile); // @Part MultipartBody.Part file
  21.  
  22. public notificationVO notifyAttachment(String token,MultipartBody.Part fileUri,final Context context){
  23.  
  24. WebservicesApi mRestAPIWService = ApiUtilsForWS.getAPIService(context,);
  25.  
  26.  
  27. Call<notificationVO> call = mRestAPIWService.notifyAttachment(token,fileUri);
  28. try {
  29.  
  30. Response<notificationVO> response = call.execute();
  31. if(response.isSuccessful())
  32. {
  33. Log.e(TAG,"Success."+response.code());
  34. return response.body();
  35.  
  36. }
  37. else
  38. {
  39.  
  40. Log.e(TAG,"Failed."+response.code());
  41. return null;
  42. }
  43.  
  44. } catch (IOException e1) {
  45. e1.printStackTrace();
  46. return null;
  47. }
  48.  
  49. }
Add Comment
Please, Sign In to add comment