![](/img/trans.png)
[英]What is the best way to send image file to server: as base64 or image file?
[英]Best way to send a long base64 string to server
我正在服务器中发送base64编码的图像。 我曾经将其存储在一个变量中,该变量将发送给服务器,但是服务器给我的响应状态为503或花费时间。 发送长字符串或压缩内容值以发送到服务器的最佳方法是什么?
第一步:将图像转换为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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.