Доброе утро, ребята уже час ломаю голову и не могу понять в чем проблема, фотка на сервер не хочет загружаться никак.
public interface UploadImageInterface {
@Multipart
@POST("/imagefolder/index.php")
Call<UploadObject> uploadFile(@Part MultipartBody.Part file, @Part("name") RequestBody name);
}
public class UploadObject {
private String success;
public UploadObject(String success) {
this.success = success;
}
public String getSuccess() {
return success;
}
}
File file = new File(filePath);
RequestBody mFile = RequestBody.create(MediaType.parse("image/*"), file);
MultipartBody.Part fileToUpload = MultipartBody.Part.createFormData("file", file.getName(), mFile);
RequestBody filename = RequestBody.create(MediaType.parse("text/plain"), file.getName());
Call<UploadObject> fileUpload = uploadImage.uploadFile(fileToUpload, filename);
fileUpload.enqueue(new Callback<UploadObject>() {
@Override
public void onResponse(Call<UploadObject> call, Response<UploadObject> response) {
Toast.makeText(MainActivity.this, "Response " + response.raw().message(), Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, "Success " + response.body().getSuccess(), Toast.LENGTH_LONG).show();
}
@Override
public void onFailure(Call<UploadObject> call, Throwable t) {
Log.d(TAG, "Error " + t.getMessage());
}
});
08-07 02:46:44.602 16819-16819/com.test.my W/System.err: java.io.FileNotFoundException: /storage/emulated/0/IMG_20170806_1627451211839253.jpg
08-07 02:46:44.603 16819-16819/com.test.my W/System.err: (No such file or directory)
08-07 02:46:44.603 16819-16819/com.test.my W/System.err: at java.io.FileInputStream.open(Native Method)