4
我試圖從Android設備上傳圖像到遠程服務器。到目前爲止,我有以下代碼,但保存在遠程服務器上的映像始終爲零字節。如何使用android拍攝圖像並存儲在服務器上
HttpURLConnection conn;
String serverpath = "http://110.172.27.47:9499";
String MREPORTER_SERVLET_PATH="/mreporter/servlet/MReporterServlet";
url = serverpath + MREPORTER_SERVLET_PATH;
try
{
URL url = new URL(serverpath + MREPORTER_SERVLET_PATH);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+ "*****");
conn.setRequestProperty(USER_NAME_REQUEST_PARAMETER, "parth");
conn.setRequestProperty(EVENT_NAME_REQUEST_PARAMETER, "null");
conn.setRequestProperty(CAMERAID_REQUEST_PARAMETER, "1");
conn.setRequestProperty(ACTION_MODE_PARAMETER, "POST_DATA_ACTION");
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
Log.i("Response", conn.getResponseCode() + "");
int response = conn.getResponseCode();
if (response == 200)
{
Log.i("size",data.length + "");
if (data.length > 0)
{
dos.write(data);
Log.i("200","OK");
}
else
{
Log.i("Error", response + "");
}
}
不要把你的答案作爲評論給出一個適當的規範(如果你知道的話),所以它對其他人也有用 – darshan 2012-04-27 06:02:10