I have been following this great tutorial and got my codes to working with most of the database transfers. Now I’d like to use the same method to update long text messages and images onto my server MySQL database, but it doesn’t seem to work.
NSString *strURL = [NSString stringWithFormat:@"http://mydomain.com/sync.php?name=%@&message=%@&image=%@",nameField.text, messageField.text, image];
and then
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];
NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"StrResult is... %@", strResult);
Problem 1: When the messageField.text is a long text with blank spacing in between such as “This is a free text format with up to 1000 characters…” , it will cause strURL to have blank spaces as well, and thus strResult will become null.
Problem 2: image is of blob format which I already saved in the local sqlite. I’m not even sure if transferring this way is a good idea. But basically I want to upload the image from iPhone/iPad straight onto a server MySQL database.
Hope someone could help me with either one of these 2 problems. Or are there any better and easier alternatives to update MySQL on my server? Thank you!
Problem 1 : When you are sending parameters through a GET request, you need to escape your parameters to avoid illegal characters. By the way, you can not send unlimited data with this kind of request. For a large amount of data, you should rather use a POST request.
Problem 2 : ASIHTTPRequest is a wrapper used to communicate with remote servers. If you choose to use it (I encourage you to do), here is the documentation that you will need to POST a request . There is also an example to send an image to a remote server with NSData.