如何使用Volley发送multipart / fom-data并在JSON对象中获取响应?

时间:2022-10-22 20:27:47

I have a functionnal Android app send request with Volley and get response in JsonObject. Now, I need to include an image in my request and I don't have any idea how I can do that, and still receive my response in a JsonObject.

我有一个功能Android应用程序发送请求与Volley并在JsonObject中获得响应。现在,我需要在我的请求中包含一个图像,我不知道如何做到这一点,并且仍然在JsonObject中收到我的响应。

Thank you for helping.

感谢您的帮助。

Fabien.

1 个解决方案

#1


1  

        JsonMultipartRequest<Upload> request = new JsonMultipartRequest<Upload>(Method.POST, apiUrl, mListener, mErrorListener);

        request.addFile("photo", image_path);

        RequestQueue mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        mRequestQueue.addRequest(request);
        mRequestQueue.start();

JsonMulitpartRequest is extended class of MultipartRequest where Override the below method to make it JSON object parseNetworkResponse

JsonMulitpartRequest是MultipartRequest的扩展类,其中覆盖以下方法使其成为JSON对象parseNetworkResponse

This is using library VolleyPlus

这是使用图书馆VolleyPlus

#1


1  

        JsonMultipartRequest<Upload> request = new JsonMultipartRequest<Upload>(Method.POST, apiUrl, mListener, mErrorListener);

        request.addFile("photo", image_path);

        RequestQueue mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        mRequestQueue.addRequest(request);
        mRequestQueue.start();

JsonMulitpartRequest is extended class of MultipartRequest where Override the below method to make it JSON object parseNetworkResponse

JsonMulitpartRequest是MultipartRequest的扩展类,其中覆盖以下方法使其成为JSON对象parseNetworkResponse

This is using library VolleyPlus

这是使用图书馆VolleyPlus