我是新的改造我想用不同的參數,如名稱,dob,手機上傳單個圖像。我不知道我在哪裏錯了請指導我。我按照這個LINKRetrofit 2.0.2圖像上傳使用多部分
這裏是我的代碼
接口
@Multipart
@POST("signup")
Call<ResponseBody> getSignup(@Part("name") RequestBody name, @Part("email") RequestBody email, @Part("dob") RequestBody dob, @Part("phone") RequestBody phone, @Part("IMEI") RequestBody IMEI, @Part MultipartBody.Part file);
上傳代碼
// create RequestBody instance from file
RequestBody requestFile =
RequestBody.create(MediaType.parse("multipart/form-data"), file);
// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part body =
MultipartBody.Part.createFormData("image", file.getName(), requestFile);
RequestBody name =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_name.getText().toString());
RequestBody email =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_email.getText().toString());
RequestBody dob =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_dob.getText().toString());
RequestBody mobile =
RequestBody.create(
MediaType.parse("multipart/form-data"), et_mobile.getText().toString());
RequestBody imei =
RequestBody.create(
MediaType.parse("multipart/form-data"), IMEI);
Call<ResponseBody> responseBodyCall = apiInterface.getSignup(name, email, dob, mobile, imei, body);
responseBodyCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
String response_two = response.body().toString();
Log.i(TAG, "onResponse: " + response_two);
// startActivity(new Intent(this, OTPActivity.class));
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.e("Upload error:", t.getMessage());
}
});
您有什麼問題
interface
打電話? – Nithinlal
我不想上傳多個文件只有一個文件我想發送。 –
我無法上傳與移動,名稱,imei等不同參數的文件。 –