Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring image BLOB in database from iOS through PHP
    primarykey
    data
    text
    <p>I'm trying to send new picture from <code>iOS</code> to database using PHP.</p> <p>I'm getting a zero byte <strong>BLOB</strong> in the <code>DATABASE</code>... Any help would be greatly appreciated :)</p> <p>CODE:</p> <pre><code>NSString *url = @"-----------------"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]]; [request setHTTPMethod:@"POST"]; NSData *binaryData = UIImageJPEGRepresentation(image, 1.0); NSString *encodedString = [binaryData base64Encoding]; //NSLog(@"Encoded : %@ ",encodedString); //NSData* binaryData = UIImagePNGRepresentation(image); NSString *bodyString = [NSString stringWithFormat:@"image=%@",encodedString]; [request setValue:[NSString stringWithFormat:@"%d", [bodyString length]] forHTTPHeaderField:@"Content-length"]; [request setHTTPBody:[bodyString dataUsingEncoding:NSASCIIStringEncoding]];//or set the type of encoding agreed with your webservice NSURLResponse *response = nil; NSError *error = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;response error:&amp;error]; NSString *responseString; if ( responseData &amp;&amp; !error){ responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"Response: %@",responseString); } </code></pre> <p>PHP: <pre><code>$json_obj = json_decode($_POST['image']); $blob = base64_decode($json_obj); $dbHandle = mysql_connect("MYCONNECTION"); $dbFound = mysql_select_db("MYCONNECTION"); if($dbFound){ $check = "INSERT INTO `Images`(`imageId`, `image`, `userId`, `dateCreated`) ". "VALUES ". "('','$blob','0',null)"; $retval = mysql_query( $check, $dbHandle ); if(!$retval) { die('Could not enter data: ' . mysql_error()); } echo "BLOB: " . $blob; } else{ print "No Connection"; } mysql_close($dbHandle); ?&gt; </code></pre> <p>The output I'm getting:</p> <pre><code>Response: BLOB: </code></pre> <p>And Getting New BLOB in database </p> <pre><code>[BLOB - 0B] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload