Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

saqibjaan

macrumors member
Original poster
Feb 1, 2012
48
1
Lahore
I am trying to upload jpg file from my Mac to a PHP website. I am using 3rd party library (ASIHTTPRequest) to upload a file. Here is the code.


Code:
-(void) upload
{

    NSURL *url = [NSURL URLWithString:
				   
                  @"http://dashboard3.mobistealth.com:8080/bbUploadFile.php?
                                             type=rest&u=mobistealth-
                       [email]rest@mobistealth.com[/email]&p=9QhDuIZ65TWc&name=saqib"];
	

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] 
                                                  initWithURL:url] autorelease];
	
	[request setPostValue:@"fileName" forKey:@"318833423305784.jpg"];
	
	[request setFile:@"/Users/User/Documents/318833423305784.jpg"    
                                                 forKey:@"photo"];
	
	
	
	[request startSynchronous];
	
	NSError *error = [request error];
	
	if(!error)
	{
		NSString *response = [request responseString];
		NSLog(@"%@", response);
	}
	
	int statusCode = [request responseStatusCode];
	NSLog(@"%i", statusCode);
}



I get the following output and pic doesn't upload.


2012-08-14 09:03:47.551 screenCapture[300:a0f] <html><head><title>Apache Tomcat/7.0.26 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 400 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The request sent by the client was syntactically incorrect ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.26</h3></body></html>
2012-08-14 09:03:47.555 screenCapture[300:a0f] 400
 
Last edited by a moderator:
I don't know this library but I can see a couple problems off the bat.

[request setPostValue:mad:"fileName" forKey:mad:"318833423305784.jpg"];

This is backwards. filName should be the key and the actual file name should be the value.

I.e.

[request setPostValue:mad:"318833423305784.jpg" forKey:mad:"fileName"];

Also I'm fairly sure you're supposed to read the data into an NSData object and append that to your request. See the answers on this Stack Overflow thread for examples:

http://stackoverflow.com/questions/...es-with-uploading-a-file-using-asihttprequest
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.