私は多くのstackoverflowの回答を見てきましたが、画像をアップロードできませんでした。それは私を与えるために使用されたInternal Server Error
。今私はsolutionを見つけましたが、ヌルイメージをサーバーに送信します。私が間違っているところを教えてください。retrofitで画像をアップロードするには?
@Multipart
@POST("lostandfound")
Call<ResponseBody> uploadLostAndFound(@PartMap Map<String, RequestBody> map);
そして、私のCALL:
Map<String, RequestBody> map = new HashMap<>();
map.put("usermail", toRequestBody("mohammad_sed"));
map.put("content", toRequestBody(content));
map.put("islost", toRequestBody(String.valueOf(isLost)));
map.put("wasfound", toRequestBody(foundPlace));
map.put("tofind", toRequestBody(toFindPlace));
File file = new File(destination);
RequestBody reqFile = RequestBody.create(MediaType.parse("image"), file);
MultipartBody.Part body = MultipartBody.Part.createFormData("upload", file.getName(), reqFile);
map.put("img", body);
ForumService client = Utils.getBuilder().create(ForumService.class);
Call<ResponseBody> call = client.uploadLostAndFound(map);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()) {
mProgressDialog.dismiss();
// Toast.makeText(getApplicationContext(), "Request created", Toast.LENGTH_SHORT).show();
} else {
mProgressDialog.dismiss();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
mProgressDialog.dismiss();
Toast.makeText(getApplicationContext(), "Failed to upload!", Toast.LENGTH_SHORT).show();
}
});
// This method converts String to RequestBody
public static RequestBody toRequestBody(String value) {
RequestBody body = RequestBody.create(MediaType.parse("text/plain"), value);
return body;
}
は、私が試した:
@Multipart
@POST("lostandfound")
Call<ResponseBody> uploadLostAndFound(@Part MultipartBody.Part photo,
@PartMap Map<String, RequestBody> map);
しかし、私はInternal server error
を取得し、このよう
は、ここに私の要求コードです。
ありがとうございます。
"内部サーバーエラー" - > "サーバーエラー" - > "サーバー"。問題はサーバコード –
で、傍受者のモバイルリクエストで郵便受けログを試して、両方のリクエストの間の違いを確認してください。 – tebitoq