我想发送存储在内部存储中的PDF文件(InternalStrorage / PDF / OCK.pdf)
我已经使用Android Volley将字符串数据发送到我的php服务器而没有问题通过此功能:
private void upload(){
StringRequest stringRequest = new StringRequest(Request.Method.POST, UploadURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String Response = jsonObject.getString("response");
Toast.makeText(getApplicationContext(),Response, Toast.LENGTH_LONG).show();
selectedimage.setImageResource(0);
selectedimage.setVisibility(View.GONE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("date",DateFormat.getDateTimeInstance().format(new Date()).toString());
params.put("description",editTextDescription.getText().toString());
params.put("statut", whatstatutis());
params.put("action",editTextImediatActionTaken.getText().toString());
return params;
}
};
MySingleton.getInstance(getApplicationContext()).addTorequesteque(stringRequest);
}
我想在同一时间发送包含我的数据的PDF文件。
答案 0 :(得分:0)
最后我找到了解决方案。 1-只需将PDF转换为字节数组即可 2-字节数组到base64 3-像普通字符串一样发送
byte[] data = null;
File filessss = new File(Link_Of_The_PDF.pdf);
try {
data = FileUtils.readFileToByteArray(filessss);
} catch (IOException e) {
e.printStackTrace();
}
return Base64.encodeToString(data, Base64.DEFAULT);