简体   繁体   中英

Best way to send a long base64 string to server

i'm sending a base64 encoded image in server. i used to store it in a variable that i'll send in post to the server, but my server gives me a 503 response status or take time. what's a best way to send a long string or to compress the value of content to send to the server?

First Step : convert image to Base64 string

byte[] bytes = new byte[(int)file.length()];
    FileInputStream fileInputStreamReader = getFileStream();
    fileInputStreamReader.read(bytes);
    return new String(Base64.encodeToString(bytes, Base64.DEFAULT));

Second Step send Request

Base64UploadRequest request = new Base64UploadRequest(this, uploadId,  ApiConfig.UPLOAD_HOST + "/raw");
        request.addHeader("Connection", "keep-alive");
        request.addHeader("Keep-Alive", "timeout=600, max=100");
        request.addHeader("Content-Type", "application/x-www-form-urlencoded");
        request.addParameter("source", base64String());
        request.addParameter("extension", extension);
        request.setNotificationConfig(getNotificationConfig("Envoie des photos"));
        request.setMaxRetries(3);
        request.startUpload();

But the server take time when the base64 string is too long

get_client_block(102400) failed
Internal error on sending request(POST //raw HTTP/1.1); uri(/public/index.php?/raw) content-length(361157): SendRequest: prepare(): user_get_body(bodyLocalBuf, 102400): read from client failed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM