Guest User

Untitled

a guest
Oct 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. photoFiles = new ArrayList<File>();
  2. MultipartBody.Builder requestBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
  3. int index = 0;
  4. for(Bitmap bitmap: previewBitmaps)
  5. {
  6. File file = null;
  7. try{
  8. String fileName = String.valueOf(System.currentTimeMillis())+".jpeg";
  9. file = new File(Environment.getExternalStorageDirectory(), fileName); // create temporary file start from here
  10. if(file.exists())
  11. {
  12. file.delete();
  13. }
  14. OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
  15. bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
  16. os.close();
  17.  
  18. photoFiles.add(file);
  19. requestBodyBuilder.addFormDataPart("files",file.getName(), RequestBody.create(MediaType.parse("image/png"),file));
  20. }
  21. catch (Exception e)
  22. {
  23. Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
  24. }
  25. index++;
  26. }
  27. //Upload process goes here and delete files back after upload
  28.  
  29. photoFiles = new ArrayList<File>();
  30. MultipartBody.Builder requestBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
  31. int index = 0;
  32. for(Bitmap bitmap: previewBitmaps)
  33. {
  34. File file = null;
  35. try{
  36.  
  37. Uri uri = Uri.parse(photosUriStrings.get(index));
  38. file = new File(getPathFromUri(uri));
  39. Toast.makeText(getBaseContext(),getPathFromUri(uri),Toast.LENGTH_SHORT).show();
  40. photoFiles.add(file);
  41. requestBodyBuilder.addFormDataPart("files",file.getName(), RequestBody.create(MediaType.parse("image/png"),file));
  42. }
  43. catch (Exception e)
  44. {
  45. Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
  46. }
  47. index++;
  48. }
  49.  
  50. Picasso.with(getContext()).load("URI path").into(holder.imgID);
Add Comment
Please, Sign In to add comment