首先,我需要使用Volley库上传文件,我找到一个并且效果很好。但是,如果我没有设置文件它不起作用。这意味着如果MATCH (n)...
WHERE...
WITH n
MATCH p=(n)-[*0..d]-()
RETURN p
为空,则所有其他实体都不会请求。
model.getFile()
感谢您的帮助。
的编辑:
如果我删除public class MultipartRequest extends Request<JSONObject> {
private MultipartEntity entity = new MultipartEntity();
private final Response.Listener<String> mListener;
private HashMap<String, String> mParams;
QuestionModel model;
Activity activity;
public MultipartRequest(String url, Response.ErrorListener errorListener, Response.Listener<String> listener, QuestionModel model, Activity activity) {
super(Method.POST, url, errorListener);
mListener = listener;
this.activity = activity;
this.model = model;
buildMultipartEntity();
}
private void buildMultipartEntity() {
try {
entity.addPart("theme_id", new StringBody(model.getThemeID()));
if (model.getText() != null) {
entity.addPart("text", new StringBody(model.getText()));
} else {
entity.addPart("text", new StringBody("file"));
}
} catch (UnsupportedEncodingException e) {
VolleyLog.e("UnsupportedEncodingException");
}
if (model.getFile() != null) {
entity.addPart("file", new FileBody(new File(model.getFile())));
}
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String creds = String.format("%s:%s", Const.PHONE_NUMBER_VALUE, Const.getPassword());
String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
params.put("Authorization", auth);
if (model.getFile() != null) {
params.put("Content-Type", "multipart/form-data");
} else {
params.put("Content-Type", "application/x-www-form-urlencoded");
}
return params;
}
@Override
public String getBodyContentType() {
return entity.getContentType().getValue();
}
@Override
public byte[] getBody() throws AuthFailureError {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
entity.writeTo(bos);
} catch (IOException e) {
VolleyLog.e("IOException writing to ByteArrayOutputStream");
}
return bos.toByteArray();
}
@Override
protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
try {
String jsonString = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
return Response.success(new JSONObject(jsonString),
HttpHeaderParser.parseCacheHeaders(response));
} catch (UnsupportedEncodingException e) {
return Response.error(new ParseError(e));
} catch (JSONException je) {
return Response.error(new ParseError(je));
}
}
@Override
protected void deliverResponse(JSONObject response) {
mListener.onResponse(response.toString());
}
}
更改为文件没有设置它工作但如果文本cyrilic不工作在这种情况下