我将你的代码@RacZo和@BNK重写为更模块化和易于使用的
VolleyMultipartRequest multipartRequest = new VolleyMultipartRequest(Request.Method.POST, url, new Response.Listener<NetworkResponse>() { @Override public void onResponse(NetworkResponse response) { String resultResponse = new String(response.data); // parse success output }}, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { error.printStackTrace(); }}) { @Override protected Map<String, String> getParams() { Map<String, String> params = new HashMap<>(); params.put("api_token", "gh659gjhvdyudo973823tt9gvjf7i6ric75r76"); params.put("name", "Angga"); params.put("location", "Indonesia"); params.put("about", "UI/UX Designer"); params.put("contact", "angga@email.com"); return params; } @Override protected Map<String, DataPart> getByteData() { Map<String, DataPart> params = new HashMap<>(); // file name could found file base or direct access from real path // for now just get bitmap data from ImageView params.put("avatar", new DataPart("file_avatar.jpg", AppHelper.getFileDataFromDrawable(getbaseContext(), mAvatarImage.getDrawable()), "image/jpeg")); params.put("cover", new DataPart("file_cover.jpg", AppHelper.getFileDataFromDrawable(getbaseContext(), mCoverImage.getDrawable()), "image/jpeg")); return params; }};VolleySingleton.getInstance(getbaseContext()).addToRequestQueue(multipartRequest);
VolleyMultipartRequest在我的要旨中检查完整的代码。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)