Java 将图片上传到android服务器
我必须捕获图像,并使用2将其上传到服务器 我的API 但问题是Uri路径是file://而不是content://因此contentType为nullJava 将图片上传到android服务器,java,android,Java,Android,我必须捕获图像,并使用2将其上传到服务器 我的API 但问题是Uri路径是file://而不是content://因此contentType为null 你知道当我把照片上传到服务器而不是照片文件URLfile:///storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg 将此文件传递给/storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jp
你知道当我把照片上传到服务器而不是照片文件URL
file:///storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg
将此文件传递给
/storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg
而不是照片文件URLfile:///storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg
通过这个/storage/simulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg
@Multipart
@POST("photo/")
Call<NetWorkResponse<String>> uploadPhoto(@Header("Authorization") String token,
@Part("category") String category,
@Part MultipartBody.Part photo);
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) {
}
});
}
File f = new File(mCurrentPhotoPath);
Uri pictureUri = Uri.fromFile(f);
String contentType = getContentResolver().getType(pictureUri);
MediaType.parse(contentType)