我目前正在尝试从 AVD 将文件/图像上传到我的 apache 服务器。执行代码时没有出现任何错误,但图像未上传到服务器。我已经更改了 apache 服务器上文件夹的权限,该文件夹
http://10.0.2.2/images
可由其他用户写入和编辑。我遇到了这个问题,请帮忙。跟随是我的代码
此代码获取图像并解码为位图。
bmp = BitmapFactory.decodeFile(filePath);
以下是我运行以将文件上传到服务器的代码
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Bitmap tmpbmp = bmp;
tmpbmp.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(url);
ByteArrayBody bab = new ByteArrayBody(data, "test.jpg");
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploaded", bab);
reqEntity.addPart("photoCaption", new StringBody("aaaa"));
postRequest.setEntity(reqEntity);
HttpResponse httpResponse = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {
s = s.append(sResponse);
}
Log.i("wi", "Response: " + s);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
Log.i("wi", "Encoding failed: " + e);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.i("wi", "client protocol exception!: " + e);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("wi", "IO Exception!: " + e);
}
我收到了来自 Log.i("wi", "Response: " + s); 的回复 =
Response: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html> <head>
<title>Index of /images</title> </head> <body><h1>Index of /images</h1><ul><li><a
href="/"> Parent Directory</a></li></ul></body></html>
它没有上传文件。