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.
 
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?
 
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:]
 
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)
 
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.