0
Je veux envoyer un fichier PDF stocké dans la mémoire interne (InternalStrorage/PDF/OCK.pdf)Android Envoi PDF au serveur en utilisant Volley
J'ai déjà envoyé Chaîne de données à mon serveur PHP en utilisant Volley Android sans problème via cette fonction :
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);
}
Je veux envoyer le fichier PDF avec mes données dans le même temps.
Essayez multipart entité. Les fichiers peuvent être envoyés en utilisant multipart. –
@AshishJohn avez-vous un excellent tutoriel ou un lien utile? –
Ou vous pouvez suivre: 1. Convertir un fichier pdf à tableau d'octets 2. tableau d'octets à un tableau base64 encode octets octet [] encodedBytes = Base64.encodeBase64 (origByteArr) et Chaîne base64Str = new String (encodedBytes); Envoyez-le en utilisant une bibliothèque de mise en réseau disponible à votre bout – Napolean