使用MultipartEntity进行排球请求

时间:2016-09-26 13:26:26

标签: android post android-volley image-uploading multipartentity

我想借助 排球 (POST)上传图片文件。
我的请求已经工作了,我做了 JSONObject ,可以连接到url并为我的数据发布标题和描述。
现在我想使用 MultipartEntity 在下一级添加图像。
我已经红了好几个帖子了 https://stackoverflow.com/,但没有到达任何地方。 我的日程安排有点紧张,需要你的帮助 任何帮助将不胜感激。谢谢你们所有人。

    public void postData(Context applicationContext, String title, String note, String imagePath , String imageDescription, final Listeners.APIPostDataListener listener) {
    //Instantiate the RequestQueue.
    RequestQueue queue = Volley.newRequestQueue(applicationContext);
    Settings settings = new Settings(applicationContext);
    String selectedURL = settings.getChosenUrl();
    final String token = settings.getTokenKey();
    String url = "http://" + selectedURL + "/databox/api/v1/upload/files";
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("Content-Disposition", "form-data");
    File file = new File(imagePath);

    try {
        MultipartRequest mr = new MultipartRequest(url, new Response.Listener<String>() {

            @Override
            public void onResponse(String response) {
                Log.d("response", response);
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Volley Request Error", error.getLocalizedMessage());
            }

        }, file, params){
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("Authorization", "Bearer " + token);
                //params.put("Content-Type", "multipart/form-data");
                return params;
            }
        };
        queue.add(mr);
    }catch(Exception exception){
        Log.e("postData",exception.getMessage());
    }

我更改了代码,现在我收到了服务器错误。

0 个答案:

没有答案