我正在做一个项目,我必须将图像文件作为 BLOB 数据从 iOS 应用程序和 android 应用程序上传到 MySQL 数据库。我使用了以下代码
对于 iOS:
imageData = UIImageJPEGRepresentation(croppedImage, 0.9);
以下代码正在插入图像数据:
NSString *encodedString = [[imageData base64Encoding] urlEncodeUsingEncoding:NSUTF8StringEncoding];
NSString *insertURL = [NSString stringWithFormat:[[@"http://" stringByAppendingString:IP]stringByAppendingString: @":8888/MasterTableInsert.php?id=%@&pf=%@&coord=%@&ct=%@"],[processID urlEncodeUsingEncoding:NSUTF8StringEncoding],encodedString ,[locationCoor urlEncodeUsingEncoding:NSUTF8StringEncoding],[currentTimeInString urlEncodeUsingEncoding:NSUTF8StringEncoding]];
php 脚本与此处显示的相同
对于安卓
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,90, stream);
byte[] byte_arr = stream.toByteArray();
String image_str = new String(Base64.encode(byte_arr,Base64.DEFAULT));
System.out.println(camTime + "picture taken time");
System.out.println(image_str + "image encoded string");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id",encodedPid));
nameValuePairs.add(new BasicNameValuePair("coord",loc));
nameValuePairs.add(new BasicNameValuePair("ct",camTime));
nameValuePairs.add(new BasicNameValuePair("pf", image_str));
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(constants.URL + "MasterTableInsertJava.php" );
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF_8"));
HttpResponse response = httpClient.execute(httpPost);
PHP 代码与此处显示的相同
我看到的问题是,对于 iOS,任何超过 5kib 的 BLOB 内容都不会插入到表中,但是对于 android,即使 BLOB 内容大小约为 20kib 及以上,它也可以正常工作。知道为什么会发生这种情况吗?我做错什么了吗?