我正在尝试使用排球库上传图片,我不知道究竟是怎么回事。
我已经提到了之前提出的问题,但似乎没有什么能满足。
这是我需要实现的目标:
以下是我尝试使用的代码:
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("**********", " Response Received is " + response);
try {
JSONObject jsonObject = new JSONObject(response);
Log.d("**********", "STRING TO JSON CONVERSION DONE , IT IS " + jsonObject.toString());
ParseReqOtp parseReqOtp = new ParseReqOtp();
parseReqOtp.parseImageupload(jsonObject);
} catch (Exception e) {
Log.d("**********", "ERROR IN STRING TO JSON CONVERSION " + e.toString());
}
Log.d("**********", "FETCHING IN VOLLEY REQ" + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(AddPic.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected HashMap<String,String> getParams() {
HashMap<String, String> params = new HashMap<String, String>();
params.put("id", BaseActivity.getBaseActivity().getEstablishment_id());
params.put("type", "photos");
params.put("example_file",file.toString());
}
};
答案 0 :(得分:0)
private void uploadImageWithStringParamsToServer() {
SimpleMultiPartRequest smr = new SimpleMultiPartRequest(Request.Method.POST, "http://139.59.16.103/addImage",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("Response", response);
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
});
smr.addStringParam("id", "821470");
smr.addStringParam("type", "photos");
smr.addFile("example_file", "2014-11-17 17.08.33-2.jpg");
smr.setFixedStreamingMode(true);
smr.setOnProgressListener(this);
RequestQueue mRequestQueue = Volley.newRequestQueue(this);
mRequestQueue.add(smr);
mRequestQueue.start();
}