Android Having Problems While Uploading Images Using Retrofit Multipart?
I'm getting the following error while trying to upload an Image to a server using retrofit, the api receives a header authorization token, _method = 'put' and image = 'imageName.jp
Solution 1:
For Below Android 6.0 Marshmallow :
Add Permission in Manifest :
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
For Marshmallow and Above Device's:
public class MainActivity extends AppCompatActivity implements ActivityCompat.OnRequestPermissionsResultCallback{
private static final int REQUEST_WRITE_PERMISSION = 786;
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_WRITE_PERMISSION && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
openFilePicker();//do your job
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestPermission();
}
private void requestPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION);
} else {
openFilePicker();//do your job
}
}
}
For more info see below link's
Android 6.0 Marshmallow. Cannot write to SD Card
Read and Write permission for storage and gallery usage for marshmallow
Note: Do not forget to add permission in manifest file
Solution 2:
Add this
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
inside the manifest tag of your manifest file.Makes sure its outside the application tag however.
Post a Comment for "Android Having Problems While Uploading Images Using Retrofit Multipart?"