장치 파일 시스템에서 서버로 이미지를 업로드하려고합니다. WIFI 연결을 사용하면 업로드가 정상적으로 작동하지만 GPRS 일 때는 업로드가 실패합니다. 내 코드는 다음과 같습니다 :HttpUrlConnection을 사용하여 이미지 업로드
String request=null;
byte[] attachmentData;
//read the image from the file system
attachmentData=bytesReadfromthefilesystem;
//I use Apache's Base64 encoding to convert the byte array to string
request=Base64.encode(data);
URL url = new URL(
"http://mydomain.com:9090//abc/http?ID=12345");
HttpURLConnection httpURLConnection = (HttpURLConnection) url
.openConnection();
httpURLConnection.setRequestProperty("Content-Type",
"text/plain");
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setChunkedStreamingMode(0);
httpURLConnection.connect();
OutputStream outStream outStream =httpURLConnection.getOutputStream();
if (outStream != null) {
if (request.getData().length() > 0) {
outStream.write(request.getBytes());
}
outStream.flush();
outStream.close();
outStream = null;
}
이미지 크기가 1MB에 가깝습니다. 나는 삼성 갤럭시 팝 (안드로이드 2.2.1)에 노력하고있어. 나는 어떤 오류도 얻지 않는다. 내가 여기서 뭔가를 놓치고 있니? 누군가가 친절하게 나를 도울 수 있었습니까? 미리 감사드립니다.
"업로드 실패"정의 : – dimsuz
이미지를 업로드하려고하는 서버에 도달하지 못했습니다. :) –