I was working on a project where I had to upload an image file as BLOB data to a MySQL database from an iOS app and an android app. I used the following code
for iOS:
imageData = UIImageJPEGRepresentation(croppedImage, 0.9);
and the following code was inserting the image data:
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]];
The php scripts is the same as shown here
for android
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);
and the PHP code is same as shown here
The problem i see is, with iOS any BLOB content of more than 5kib is not inserted into the table, however with android it works fine even if the BLOB content size is around 20kib and plus. Any idea why would this happen? Am I doing anything wrong?