2014-11-29 2 views
0

Base64 변환을위한 데모 앱을 만들고 있습니다. base64를 올바르게 변환하는 이미지가 있습니다. 이미지 크기가 3.92Mb (4128 * 3096) 일 때 성공적으로 생성 된 base64로 변환하고 서버에 업로드하지만 업로드되지 않은 경우 Base64 문자열 쓰기 후 파일 및 텍스트 파일 크기는 5.40Mb입니다. 이미지 Convet에 대한 코드 아래 이미지를 Base64로 변환하는 문제

public String convertImage(File file) { 

    FileInputStream inputSteam = new FileInputStream(file); 
    inputSteam.read(getBytesFromFile(file)); 

    return Base64.encodeToString(getBytesFromFile(file, Base64.DEFAULT); 
} 


public byte[] getBytesFromFile(File file) throws IOException { 

    InputStream is = new FileInputStream(file); 
    // Get the size of the file 
    long length = file.length(); 

    // You cannot create an array using a long type. 
    // It needs to be an int type. 
    // Before converting to an int type, check 
    // to ensure that file is not larger than Integer.MAX_VALUE. 
    if (length > Integer.MAX_VALUE) { 

     // File is too large 
    } 

    // Create the byte array to hold the data 
    byte[] bytes = new byte[(int) length]; 

    // Read in the bytes 
    int offset = 0; 
    int numRead = 0; 
    while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { 
     offset += numRead; 
    } 

    // Ensure all the bytes have been read in 
    if (offset < bytes.length) { 

     throw new IOException("Could not completely read file "+ file.getName()); 
    } 

    // Close the input stream and return bytes 
    is.close(); 
    return bytes; 
} 

이 문제를 처리하는 방법을 Base64로합니다. 또는 이미지를 변환하는 다른 방법; 당신이 서버로 PHP를 사용하는 경우

답변

0

, 당신은 64 기수를 유지하기위한 base64 인코딩 문자열에서 자신의 캐릭터를 추가하기 때문에

0

base64로 문자열 파일이 원본 파일 크기보다 커야한다 php.ini 파일 업로드 파일의 최대 크기를 확인 않았다 체재. 그래서 이것이 더 큰 파일 크기와 원래 크기의 문제 일 수 있습니다.

+0

이미지 처리를위한 다른 솔루션 – Sanket990

+0

[link] (http://stackoverflow.com/questions/21306720/uploading-image-from-android-to-php-server) pls이 링크가 도움이 될 수도 있습니다. . –

관련 문제