Reputation: 27
I am having problems uploading a data file to a server. On the objective-c side everything seems to be working (I enabled a progress bar which slowly increases to 100%). Here is the code (you can assume uploadURL is the correct URL and outFilePath is the correct path to the file "out.txt", I have doubled checked this):
ASIFormDataRequest *uploadRequest = [ASIFormDataRequest requestWithURL:uploadURL];
[uploadRequest setUploadProgressDelegate:uploadProgress];
[uploadRequest setFile:outFilePath forKey:@"file"];
[uploadRequest startSynchronous];
The server does not seem to be receiving the data file. Here is the php code (which I did not write):
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]$
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
?>
Any ideas on what I'm doing wrong would be appreciated. Thanks!
Upvotes: 0
Views: 1029
Reputation: 18830
if i run this code (taken from ASIHTTP examples)
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://buildmac.ee.pitt.edu/~wsn/boinclite/upload_file"];
[request setPostValue:@"test" forKey:@"value1"];
[request setPostValue:@"test" forKey:@"value2"];
[request setPostValue:@"test" forKey:@"value3"];
[request setTimeOutSeconds:20];
//Create a 256KB file
NSData *data = [[[NSMutableData alloc] initWithLength:256*1024] autorelease];
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"file"];
[data writeToFile:path atomically:NO];
[request setFile:path forKey:@"file"];
[request startAsynchronous];
i get this as a result (using Charles Proxy to monitor the upload):
Upload: file
Type: application/octet-stream
Size: 256 Kb
Temp file: /private/var/tmp/phpi6UDp1
Stored in: upload/file
so everything is running as it should.
Upvotes: 2