我在服务器中发送base64编码的图像。 我曾经将它存储在一个变量中,我将其发送到服务器, 但我的服务器给了我503响应状态或花时间。 什么是发送长字符串或压缩要发送到服务器的内容值的最佳方式?
答案 0 :(得分:0)
第一步:将图像转换为Base64字符串
byte[] bytes = new byte[(int)file.length()];
FileInputStream fileInputStreamReader = getFileStream();
fileInputStreamReader.read(bytes);
return new String(Base64.encodeToString(bytes, Base64.DEFAULT));
第二步发送请求
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();
但是当base64字符串太长时服务器需要时间
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