-1

How to upload NSData Object to server with specific name ?

NSData *imgData; // Image Data
NSString *imgName = @"myfile.png";

I want to upload data to server with specific file name.

1. Upload Data (imgData) 

2. To server (my_server.com/upload.html) 

3. With file name (imgName)
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
ChangUZ
  • 5,380
  • 10
  • 46
  • 64

1 Answers1

0

I am currently working on a school project where I needed to do something similar to this...

I was placing longitude and latitude values in a database.

MAKE NOTE THAT THERE MAY BE MUCH SIMPLER WAYS TO DO THIS. I AM BY NO MEANS A "PRO" AT OBJECTIVE-C PROGRAMMING

There are going to be three things you need.

  1. a server in which you have access to.
  2. a PHP file that will write the data to the database.
  3. an NSURLConnection object;

I had placed the following code in one of the delegate methods for CLLocationManager.

The NSURLConnection object should look something like this:

//this is where I put the url for my PHP file
url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.example.com/folder/example.php"]];

urlRequest = [NSURLRequest requestWithURL:url];

connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];

Of course the variables: url, urlRequest, and connection are declared in the header file like this

NSURL *url;
NSURLRequest *urlRequest;
NSMutableData *filedata;
NSURLConnection *connection;   
Johnny Gamez
  • 259
  • 6
  • 19