android - 将带有 pdf 文件的用户详细信息上传到服务器
问题描述
我正在尝试实现用户投诉应用程序,这个包含用户数据和 pdf 文件的应用程序正在发送到服务器,但我失败了,请帮助我。
- 4 编辑文本
- 一键浏览
- 一个提交按钮
浏览按钮代码
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?
请帮我
解决方案
你可以使用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);
推荐阅读
- javascript - VS 代码将“它”变成“hasUncaughtExceptionCaptureCallback”。如何禁用此功能?
- server - 服务器到服务器上传
- python - 除了 sendKeys 之外,还有其他方法可以将文件上传到网站吗?
- android - 如何在 Firestore Android 中过滤多个字段
- javascript - 跨 TypeScript、nodejs 和 JavaScript 共享代码的“正确”方式
- html - css 中的溢出-x 无法正常工作
- javascript - 显示从输入类型中选择的文档:文件
- python - 允许用户使用索引位置从列表中进行选择
- python - 如果我们在二进制编码遗传算法上使用阶交叉算子会发生什么
- javascript - 将 YouTube 直播评论提取到 React 应用程序中