我正在使用此代码将图像从 android 相机上传到服务器:
miFoto = params[0];
try {
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httppost = new HttpPost("http://www.myserver.com/upload.php");
File file = new File(miFoto);
MultipartEntity mpEntity = new MultipartEntity();
ContentBody foto = new FileBody(file, "image/jpeg");
mpEntity.addPart("fotoUp", foto);
httppost.setEntity(mpEntity);
httpclient.execute(httppost);
httpclient.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
}
return null;
问题是文件大小太大。我在上传之前尝试了一些方法来压缩图像,但由于我是 android 的初学者,这对我来说是不可能的。
谢谢你。