首页 > 解决方案 > 将带有 pdf 文件的用户详细信息上传到服务器

问题描述

我正在尝试实现用户投诉应用程序,这个包含用户数据和 pdf 文件的应用程序正在发送到服务器,但我失败了,请帮助我。

浏览按钮代码

Intent intent = new Intent();
intent.setType("application/pdf");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Pdf"), PICK_PDF_REQUEST);

提交代码

String name = fil_name.getText().toString().trim();
//getting the actual path of the image
String path = FilePath.getPath(this, filePath);

如何获取文件名?

浏览的 pdf 存储在任何临时位置?

我如何通过 volley 发送 brwosed pdf?

请帮我

标签: androidsql-serverpdfandroid-volley

解决方案


你可以使用VolleyPlus

    SimpleMultiPartRequest smr = new SimpleMultiPartRequest(Request.Method.POST, URL,
        new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.d("Response", response);               
                Toast.makeText(getApplicationContext(), R.string.alert_comment_sukses, Toast.LENGTH_LONG).show();              
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
        Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
    }
});
smr.addStringParam("param string", " data text");
smr.addFile("param file", imagePath);
RequestQueue mRequestQueue = Volley.newRequestQueue(getApplicationContext());
mRequestQueue.add(smr);

推荐阅读