如何在 Android 中将文件附加到帖子网址

发布于 2024-12-27 13:44:02 字数 536 浏览 3 评论 0原文

我正在开发一个帮助台应用程序,在这个应用程序中我可以阅读并回复客户发送的票证。现在我有一个要求,我还必须上传一个文件。我有一个帖子 url 来回复票证,我将使用 Namevaluepairs 附加带有 url 的消息。

nameValuepair("id",ticketId);(nameValuepair is the instance of BasicNameValuePair)
nameValuepair("subject",subject);
nameValuepair("reply",message);

如果文件不存在,那么它将像上面的代码一样。如果文件存在,我还会为文件提供一个参数。我要做的就是附加一个文件并对其进行编码,然后将其包含到 Namevaluepair 中...

nameValuepair("file",encodedfile);

如何将文件上传到此应用程序并对其进行编码。 我得到了一些资源来使用电子邮件意图将文件附加到默认的 Android 电子邮件客户端,但这对我没有帮助。 提前致谢

I am developing a Helpdesk application, in this app I am able to read and reply for the tickets sent by the customer. Now I got a requirement, I have to upload a file also. I have a post url to reply for the ticket, I will use Namevaluepairs to attach message with the url..

nameValuepair("id",ticketId);(nameValuepair is the instance of BasicNameValuePair)
nameValuepair("subject",subject);
nameValuepair("reply",message);

If file is not there then it will be like the above code. If file is there I one more parameter comes for file. What I have to do is to attach a file and encode it and then include it into Namevaluepair...

nameValuepair("file",encodedfile);

How can I Upload the file to this app and encode it.
I got some resources to attach a file to the default android email client using email intent, that was not helpful for me.
Thanks in Advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无所的.畏惧 2025-01-03 13:44:02

上传文件比添加名称/值对更复杂。您需要获取请求的输出流并写入文件。您可以找到一个示例 这里

Uploading a file is more complicated than adding a name-value pair. You need to get the output stream of the request and write the file. You can find an example here.

南城旧梦 2025-01-03 13:44:02

使用 Apache 的 Http 客户端及其 POST 方法:

DefaultHttpClient httpclient = appContext.GetHttpClient();
HttpPost httppost = new HttpPost("your.url.com");
httppost.setEntity(new FileEntity(yourFile, PLAIN_TEXT_TYPE));
HttpResponse response = httpclient.execute(httppost);
InputStream responseStream = new ByteArrayInputStream(responseString.getBytes("UTF-8"));

Use the Http client by Apache and its POST method:

DefaultHttpClient httpclient = appContext.GetHttpClient();
HttpPost httppost = new HttpPost("your.url.com");
httppost.setEntity(new FileEntity(yourFile, PLAIN_TEXT_TYPE));
HttpResponse response = httpclient.execute(httppost);
InputStream responseStream = new ByteArrayInputStream(responseString.getBytes("UTF-8"));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文