Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Hey guys, does anybody know how to send an image (from a UIImageView) to a mysql database and then pull it back down? I know to do with text but when it comes to the image I get stuck. Any ideas? Thank you.
 

zachsilvey

macrumors 6502
Feb 5, 2008
444
3
Battle Ground
I'm not an expert with database stuff but wouldn't you be better off storing the image on the file system and only storing the path to that file in the database?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
You probably are better off storing it in the file system and keeping a reference to it in the database, but if you still want to store it in the database, easiest would be to convert to jpeg or png via UIImageJPEGRepresentation()/UIImagePNGRepresentation() and +[UIImage imageWithData:]
 

man2manno

macrumors member
Original poster
Mar 21, 2009
55
0
Ya I can convert it to the BLOB type however, I am sending it image to the server along with some text and when I go to send to them together it sends two different sets of data when I only want it to send one set of data.
Code:
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20];
		[req setHTTPMethod:@"POST"];
		[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

Code:
[req setValue:length forHTTPHeaderField:@"Content-Length"];
		[req setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];

The above code is how I am sending my text data, somehow I want to incorporate the image into my postData (which is an NSString)
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
Code:
[req setValue:length forHTTPHeaderField:@"Content-Length"];
		[req setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];

The above code is how I am sending my text data, somehow I want to incorporate the image into my postData (which is an NSString)
Well, postData may be an NSString but calling that instance method (dataUsingEncoding:) returns an NSData.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.