Ok I believe this must be a pretty common scenario. I need to send a NSData variable over a HTTP request through a PHP page which then subsequently stores it in MySQL. This will be retrieved later by some other HTTP call which then downloads it into a NSData again. What is the best way to do this?
Should I convert the NSData into some sort of string representation (base64 etc)? Should I store the data in MySQL as VARCHAR or Blob? The data length will not exceed the MySQL/HTTP limit.
You're probably going to make things much easier on yourself by Base64 encoding the data for transmission back and forth to the server. (Or yEnc, or some other ASCII encoding of the bytes.) You certainly can transmit raw bytes back and forth (after all, that's what we do with images, right?), but there's less to worry about with encodings and other HTTP headers with string data.
On the server side, then, you could store the strings in character fields in the database, you could decode them and store in BLOBs, you could save them out to the file system.... Without knowing more about the requirements of your app, it's kind of hard to say what the "best" option would be.
Easiest way is to Base64 encode the data and create a web service that lets you send the information back and forth.
Here's a category for doing Base64 encoding/decoding that I found on the web:
ECBase64.h
ECBase64.m:
1st Suggestion: you can store it in a session in PHP e.g. $_SESSION['mytext'] = <NSDATA>; don't forget to session_start(); to retrieve your string.
2nd Suggestion: you can store it in a XML FILE. That's if it supports XML
3rd Suggestion: just call it back from MYSQL to be safe.