After selecting image,doc or pdf,I want to pass them through okhttp3.How do i go about doing this?
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==RESULT_OK && requestCode==0){
Log.d("uri data",""+data.getData());
selectedFileUri = data.getData();
fileToBeUploaded = new File(""+selectedFileUri);
fileName = fileToBeUploaded.getName();
Log.d("filename",""+fileName);
And in okhttp 3
RequestBody formBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("data[User][user_picture]", fileToBeUploaded.getName(),RequestBody.create(MediaType.parse("*/*"), fileToBeUploaded))
The error showing is
java.io.FileNotFoundException: content:/com.android.providers.media.documents/document/image%3A40227: open failed: ENOENT (No such file or directory)
Thanks.
So I am answering this question myself.
So I am firstly opening an outputstream to a temporary file.
The extension depends upon the mime type.You can find the mime type by
Now to read from the file and write its contents in the temporary file
Now to write into the file
And finally
At the end after success