将图像从 Android 上传到 PHP 服务器 [英] Uploading images to a PHP server from Android

查看:26
本文介绍了将图像从 Android 上传到 PHP 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将图像上传到需要 HTTPPOST 中的以下参数的远程 PHP 服务器:

I need to upload an image to a remote PHP server which expects the following parameters in HTTPPOST:

*$_POST['title']*
*$_POST['caption']*
*$_FILES['fileatt']*

大多数互联网搜索都建议:

Most of the internet searches suggested either :

下载以下类并尝试 MultiPartEntity 发送请求:

apache-mime4j-0.5.jar
httpclient-4.0-beta2.jar
httpcore-4.0-beta3.jar
httpmime-4.0-beta2.jar

使用 URLconnection 并自己处理多部分数据.

顺便说一句,我热衷于使用 HttpClient 类而不是 java.net(或者是 android.net)类.最后,我从 Android 源代码中下载了 Multipart 类,并在我的项目中使用它们.

Btw, I am keen on using HttpClient class rather than java.net(or is it android.net) classes. Eventually, I downloaded the Multipart classes from the Android source code and used them in my project instead.

虽然这可以通过上述任何一种方法来完成,但我想确定这些是否是实现上述目标的唯一方法.我浏览了文档并找到了一个 FileEntity 类,但我无法让它工作.

Though this can be done by any of the above mentioned methods, I'd like to make sure if these are the only ways to achieve the said objective. I skimmed through the documentation and found a FileEntity class but I could not get it to work.

在 Android 应用程序中完成此操作的正确方法是什么?

What is the correct way to get this done in an Android application?

谢谢.

推荐答案

Android 源似乎带有一个内部多部分帮助程序库.查看此帖子.乍一看,它比大量公共 API(咳咳、SoundPool、咳咳)有更好的文档记录,因此它应该是一个不错的起点,或者仅使用插入式解决方案就可以了.

The Android source seems to come with an internal multipart helper library. See this post. At a quick glance, it's better documented than plenty of public APIs (cough cough, SoundPool, cough cough), so it should be a pretty good place to start, or possibly fine to just use a drop-in solution.

这篇关于将图像从 Android 上传到 PHP 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆