我有5Kb的图像,当我将其转换为Base64字符串并且我上传到我的远程数据库时,远程INSERT查询只需要几秒钟
但是..我有100Kb的图像,当我将其转换为Base64字符串并且我上传到我的远程数据库时,远程INSERT查询需要很多秒才能执行
为什么?
这是因为Base64字符串需要100KB的空间,就像非编码图像一样?
有办法解决这些等待时间吗?
更多信息:即时通讯使用PHP + JSOn连接到mysql远程数据库。
Oded使我不使用Base64并使用BLOB而不是LONGTEXT。 但....¿如何在JSON + PHP中使用BLOB?我不知道据我所知,JSON + PHP需要接收和发送字符串,而BLOB不是字符串
感谢
编辑2:
这是需要等待一段时间的代码(它在行中等待:while ((line = reader.readLine()) != null) {
,等待reader.readLine()
)
此代码从远程数据库获取一个用户,需要花费一些时间在我的应用上显示用户
public Friend RetrieveOneUser(String email)
{
Friend friend=null;
String result = "";
//the parameter data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("email",email));
//http post
InputStream is=null;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(this.BaseURL + this.GetOneUser_URL);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
//parse json data
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++)
{
JSONObject json_data = jArray.getJSONObject(i);
friend=new Friend(json_data.getString("email"),json_data.getString("password"), json_data.getString("fullName"), json_data.getString("mobilePhone"), json_data.getString("mobileOperatingSystem"),"",json_data.getString("photo"));
}
}
catch(JSONException e){
Log.e("log_tag", "Error parsing data "+e.toString());
}
return friend;
}