0
壓縮照片我使用這個代碼從Android相機的圖像上傳到服務器:上傳之前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的初學者,所以對我來說這是不可能的。
謝謝。