0

I have a signature pad in my iOS app which I am getting signed by customer and want to store image data (Content-Type: application/octet-stream) in the MySQL database using a PHP API. The image is so large that I can not pass it via API.

I am also wondering how can I retrieve this data from MySQL in the PHP application to create image?

Is this the right way to do it? Or any other standard method I should follow?

Opal
  • 81,889
  • 28
  • 189
  • 210
Amit Patel
  • 75
  • 3
  • 1
    I think it will work better to just save the uploaded image file into a directory and save the path to that image file in a text column in your database. – Don't Panic Apr 27 '15 at 14:59

2 Answers2

0

You can use ASIFormDataRequest For file uploading and save it's path or name in database instead of image data.

NSFileManager *fileManager = [NSFileManager defaultManager];

request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setRequestMethod:@"POST"];
[request setTimeOutSeconds:120];

[request setPostFormat:ASIMultipartFormDataPostFormat];
[request addRequestHeader:@"Content-Type" value:@"multipart/form-data"];  
if ([fileManager fileExistsAtPath:filePath] == YES) {

    [request setFile:filePath withFileName:@"test.png" andContentType:@"png" forKey:@"FieldName"];
}
Nilesh Kikani
  • 2,628
  • 21
  • 37
0

There are a number of things here.

On the iOS app, since you're perhaps not interested in how pretty it looks to get the file size down I would do the convert the file to black and white or greyscale and convert it as a JPG, with a low quality setting. Experiment a bit, but you can keep the size down and keep the quality acceptable. This way you can upload it much faster and within the API limits.

After uploading the file, you can save it to the MySQL database as a field (look up BLOB field type), but perhaps you're just better off keeping the file in the a persistent location in the filesystem and only save the file location to the database. See here for more information: When is using MySQL BLOB recommended?

Community
  • 1
  • 1