Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将图片上传到android服务器_Java_Android - Fatal编程技术网

Java 将图片上传到android服务器

Java 将图片上传到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

我必须捕获图像,并使用2将其上传到服务器 我的API

但问题是Uri路径是file://而不是content://因此contentType为null


你知道当我把照片上传到服务器而不是照片文件URL
file:///storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg


将此文件传递给
/storage/emulated/0/Pictures/Food/IMG_20170731_094856_2128319239.jpg

而不是照片文件URL
file:///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)