Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- photoFiles = new ArrayList<File>();
- MultipartBody.Builder requestBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
- int index = 0;
- for(Bitmap bitmap: previewBitmaps)
- {
- File file = null;
- try{
- String fileName = String.valueOf(System.currentTimeMillis())+".jpeg";
- file = new File(Environment.getExternalStorageDirectory(), fileName); // create temporary file start from here
- if(file.exists())
- {
- file.delete();
- }
- OutputStream os = new BufferedOutputStream(new FileOutputStream(file));
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
- os.close();
- photoFiles.add(file);
- requestBodyBuilder.addFormDataPart("files",file.getName(), RequestBody.create(MediaType.parse("image/png"),file));
- }
- catch (Exception e)
- {
- Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
- }
- index++;
- }
- //Upload process goes here and delete files back after upload
- photoFiles = new ArrayList<File>();
- MultipartBody.Builder requestBodyBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
- int index = 0;
- for(Bitmap bitmap: previewBitmaps)
- {
- File file = null;
- try{
- Uri uri = Uri.parse(photosUriStrings.get(index));
- file = new File(getPathFromUri(uri));
- Toast.makeText(getBaseContext(),getPathFromUri(uri),Toast.LENGTH_SHORT).show();
- photoFiles.add(file);
- requestBodyBuilder.addFormDataPart("files",file.getName(), RequestBody.create(MediaType.parse("image/png"),file));
- }
- catch (Exception e)
- {
- Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
- }
- index++;
- }
- Picasso.with(getContext()).load("URI path").into(holder.imgID);
Add Comment
Please, Sign In to add comment