Как загрузить файл с моей SDCard с путем к файлу "SDCARD / file1.pdf" на сервер php, используя залп без активности - PullRequest
0 голосов
/ 29 августа 2018

Я новичок в разработке Android. Я не знаю, как загрузить файл с определенного пути, такого как «mnt / sdcard / file.xxx» на мой php-сервер, используя залп. Как только я могу загрузить текстовые данные на мой php-сервер, используя залп. Вот мой код, который я использую, когда я вызываю pploadFile ("sdcard / file.xxx") из моего класса обслуживания.

public class UploadFiles extends Application{
RequestQueue queue;
JsonObjectRequest request;
Map<String, String> map = new HashMap<String, String>();
public void pploadFile(String path){
    Log.e("Upload Class","Inside Upload Class");
    try {
        queue = Volley.newRequestQueue(this);
        Log.e("Upload Class","Inside Upload Class1");
        // the parameters for the php
        // map.put(KEY, VALUE);
        map.put("email", "example");
        // map.put("file", "");
        // the JSON request
        // JsonObjectRequest(METHOD, URL, JSONOBJECT(PARAMETERS), OK_LISTENER, ERROR_LISTENER);
        request = new JsonObjectRequest(
                Request.Method.POST, // the request method
                "http://192.168.0.118/recieve.php", // the URL
                new JSONObject(map), // the parameters for the php
                new Response.Listener<JSONObject>() { // the response listener
                    @Override
                    public void onResponse(JSONObject response) {
                        // here you parse the json response
                    }
                },
                new Response.ErrorListener() { // the error listener
                    @Override
                    public void onErrorResponse(VolleyError error) {

                  /* here you can warn the user that there
                  was an error while trying to get the json
                  information from the php  */
                    }
                });

        // executing the quere to get the json information
        queue.add(request);
    }catch (Exception e){
        Log.e("Volley Err",e.getMessage());
    }
}
...