我的文件从图库中选取并设置为imageview,但是单击“上传”按钮后无法将文件上传到服务器上
我正在使用本地主机,我的服务器端代码正确,因为图像是通过邮递员上传的
File file = new File(mediaPath);
// parsing media type file
RequestBody requestBody1 = RequestBody.create(MediaType.parse("multipart/form-data"), file);
MultipartBody.Part fileToUpload1 = MultipartBody.Part.createFormData("input_img", file.getName(), requestBody1);
ServiceApi call = ClientApi.getData().create(ServiceApi.class);
Call<ResponseData> data = call.update(fileToUpload1);
data.enqueue(new Callback<ResponseData>()
{
@Override
public void onResponse(Call<ResponseData> call, Response<ResponseData> response)
{
ResponseData data = response.body();
if(data.getStatus().equals("true"))
{
Toast.makeText(getApplicationContext(), "yes",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "no",Toast.LENGTH_SHORT).show();
}
// Log.d("data",data.getUpdateUserData().toString());
}
@Override
public void onFailure(Call<ResponseData> call, Throwable t)
{
Toast.makeText(getApplicationContext(), "Please check once",Toast.LENGTH_SHORT).show();
}
});