gpt4 book ai didi

php - 使用 iOS 和 android 更新 Blob 数据 - 变体

转载 作者:太空宇宙 更新时间:2023-11-03 10:56:57 25 4
gpt4 key购买 nike

我在做一个项目,我必须将图像文件作为 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 脚本与显示的相同here

安卓

                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 代码与显示的相同here

我看到的问题是,对于 iOS,任何超过 5kib 的 BLOB 内容都不会插入到表中,但是对于 android,即使 BLOB 内容大小约为 20kib 或更大,它也能正常工作。知道为什么会这样吗?我做错了什么吗?

最佳答案

这两种情况的区别在于,您将图像作为 GET 参数从 iOS 发送,而在 Android 中作为 POST 发送。所以最有可能的原因是在您的服务器上设置了 URI 长度限制。您有两种可能的解决方案:

  1. 更改您的 iOS 代码以使用 POST(推荐),如 this question 的答案中所述或在 the documentation .

  2. 增加服务器上的 URI 长度限制。如果您使用的是 Apache,则需要更改或添加 LimitRequestLine directive . Apache 的默认值为 8190 字节,这与您在编码之前观察到的 5 kb 限制一致。另见 this question .

关于php - 使用 iOS 和 android 更新 Blob 数据 - 变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19697447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com