1

我正在尝试从我的 android apk 上传图像。

我使用此代码,似乎有效,但我没有收到数据响应

OkHttpClient client = new OkHttpClient().newBuilder()
            .build();

    okhttp3.RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
            .addFormDataPart("image", getBase64Image(bitmapImage))
            .build();
    okhttp3.Request request = new okhttp3.Request.Builder()
            .url("https://api.imgur.com/3/image")
            .method("POST", body)
            .addHeader("Authorization", "Client-ID " + CLIENT_ID)
            .build();

    client.newCall(request).enqueue(new okhttp3.Callback() {

        @Override
        public void onFailure(okhttp3.Call call, IOException e) {
            Log.d("ERROR",e.getMessage());
        }

        @Override
        public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException {
            //My code
        }
    });
4

0 回答 0