서버에서 Android64로 zip 파일을 Base64로 인코딩해야합니다. 파일 크기가 커서 (~ 20MB), 아래 코드를 사용하여 String을 bufferSize = 1024 * 1024로 가져 와서 인코딩하고 파일에 쓰려고합니다. android.util.Base64.encode() 메소드로 bad-base64 오류가 발생합니다. 왜?스트리밍 안드로이드 서버에서 Base64 문자열
코드 :
int bufferSize = 1024 * 1024;
byte[] buffer = new byte[bufferSize];
FileOutputStream fileOutputStream = null;
InputStream inputStream = null;
try {
fileOutputStream = new FileOutputStream(this.path + "/" + this.zipFileName);
inputStream = connection.getInputStream();
int bytesRead;
//read bytes
while ((bytesRead = inputStream.read(buffer, 0, bufferSize)) > 0) {
byte[] zipBytes = Base64.decode(buffer, 0, bytesRead, Base64.DEFAULT);
fileOutputStream.write(zipBytes);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
서버 코드를 변경할 수 있었고 이제 순수 바이트를 스트리밍하고 있습니다. – Loadeed
좋습니다! 이것이 실제로 최상의 솔루션입니다. – alexfernandez