Sagar Mohanty
Sagar Mohanty

Reputation: 237

how to use ASIHTTPRequest Class for post request to upload a text file to server?

I am working on an upload code which will upload the file to the server, which is successfully working

now what I need as fallows:

started with an example-->suppose I have a file named file.txt, whose size is 30MB, when I read the contents of the file it will give me all the 30MB it contains. In the sendSynchronousRequest method I want to give request upto 10mb of data and aging calling the same thing unless it reaches at the last point of file. (in brief I want to use a loop to send the request part by part to the server

to solve the purpose i read form http://allseeing-i.com/ASIHTTPRequest/How-to-use and Included the ASIHTTPRequest in to my project after inclusion i want to do the same , that will accept a block of data (even via a POST) then append that block of data to a file. It seems to me that you need some kind of client side app that will take a file and break it up into chunks, then send it to your web service one chunk at a time.

My problems: -how to sent a Post Request from ASIHTTPRequest with a chunk of data? -do i need to change the PHP ?

Can any one post a piece of code for both php and ASIHTTPRequest so that i can take a reference from their.

Thank you guys for your continuos support .

Upvotes: 0

Views: 1214

Answers (3)

Andres Bucci
Andres Bucci

Reputation: 947

If you use a form in the website, it would be easier to use ASIFormDataRequest instead of the standard ASIHTTPRequest. The specific details are here: Using ASIFormDataRequest

Essentially, you just create the form fields in the website and reference them when you create the request. If you have any text fields in your form you use the

[request setPostValue:@"Your value" forKey:@"form key"];

The file should be sent through the path using

[request setFile:@"filepath to needed file" forKey:@"form key"];

If you want you can also send it asynchronously and use the delegate methods for tracking the progress of the upload.

I hope this helps.

Upvotes: 1

Akhilesh Sharma
Akhilesh Sharma

Reputation: 1628

You can refer to the following link available on the stack overflow:

NSURLConnection to upload file asynchonrously?

Upvotes: 1

Alex Terente
Alex Terente

Reputation: 12036

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

From ASIHTTPRequest documentation

Upvotes: 1

Related Questions