如何在 Android 中将文件附加到帖子网址
我正在开发一个帮助台应用程序,在这个应用程序中我可以阅读并回复客户发送的票证。现在我有一个要求,我还必须上传一个文件。我有一个帖子 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上传文件比添加名称/值对更复杂。您需要获取请求的输出流并写入文件。您可以找到一个示例 这里。
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.
使用 Apache 的 Http 客户端及其 POST 方法:
Use the Http client by Apache and its POST method: