【发布时间】:2016-06-11 19:29:03
【问题描述】:
我正在使用以下任务使用 php 将多个图像从 android 设备上传到服务器。
@Override
protected String doInBackground(String... params) {
try {
String url = "http://aerialssnip.com/multipleupload.php/";
int i = Integer.parseInt(params[0]);
Bitmap bitmap = decodeFile(map.get(i));
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(url);
entity = new MultipartEntity();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,
localContext);
sResponse = EntityUtils.getContentCharSet(response.getEntity());
System.out.println("sResponse : " + sResponse);
} catch (Exception e) {
if (dialog.isShowing())
dialog.dismiss();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
return sResponse;
}
图片在安卓端和服务器端都没有任何错误上传。但是,上传的图像是 0 字节,它们没有任何数据,我无法查看它们。 php脚本
<?php
$name = $_POST["name"];
$image = $_POST["IMAGE"];
$decodedImage = base64_decode("$image");
file_put_contents($path,$decodeImage);
?>
有人知道我的代码中可能存在什么问题吗?任何帮助将不胜感激。提前致谢。
【问题讨论】:
标签: php android image-uploading