public static void uploadPhoto(String nfToken, String category, File photoFile) {
RequestBody filePart = RequestBody.create(MediaType.parse("image/jpeg"), photoFile);
MultipartBody.Part file = MultipartBody.Part.createFormData("photo", photoFile.getName(), filePart);
Call<NetWorkResponse<String>> call = nfApi.uploadPhoto(nfToken, category, file);
call.enqueue(new Callback<NetWorkResponse<String>>() {
@Override
public void onResponse(Call<NFNetWorkResponse<String>> call, Response<NetWorkResponse<String>> response) {
if (response.isSuccessful()) {
NetWorkResponse<String> netWorkResponse = response.body();
} else {
}
}
@Override
public void onFailure(Call<NetWorkResponse<String>> call, Throwable t) {
}
});
}
私の写真ファイルのURIを画像をキャプチャし、写真をアップロードするretrofit2 マイAPI
@Multipart
@POST("photo/")
Call<NetWorkResponse<String>> uploadPhoto(@Header("Authorization") String token,
@Part("category") String category,
@Part MultipartBody.Part photo);
私の方法を使用してサーバーにアップロードする必要があります。file:///storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg
ファイルをサーバーにアップロードすると、Bad Request、code 400というエラーが発生しました。これは、私のparamが間違っていることを示している可能性がありますが、何も問題はないと確信しています。私は
STHはMediaType.parse(「画像/ JPEG」)と間違っている、STHは絵が間違っていると思い代わりにそれは次のようになります。File f = new File(mCurrentPhotoPath);
Uri pictureUri = Uri.fromFile(f);
String contentType = getContentResolver().getType(pictureUri);
MediaType.parse(contentType)
しかし、問題は、URIパスがファイルであるということです。 //ないコンテンツが://そうのcontentTypeがnullである
私は、サーバーの代わりに写真ファイルのURLの