Reputation: 195
I am new to iPhone. I want to upload an image to a server. I have url
http://lifestander.com:8080/fileupload/uploadfile.html?username=tom&password=1234&directory=ebay&filename=fantacy.jpg
I use the following method for uploading the file, but the result in console is: {"success":"false", "message":"Authentication Failed"}
I do not understand the output in the console. So please tell me what do I do wrong, or improve my code. What to do?
Thanks.
-(void)uploadFile{
UIImage* theImage = [UIImage imageNamed:@"images.jpg"];
NSString* path = [[NSBundle mainBundle] pathForResource:@"images" ofType:@"jpg"];
NSString *photoUploadURLString=@"http://lifestander.com:8080/fileupload/uploadfile.html";
NSURL *url = [NSURL URLWithString: photoUploadURLString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
// Upload an image
NSData *imageData = UIImageJPEGRepresentation(theImage,1.0);
[request addPostValue:@"tom" forKey:@"username"];
[request addPostValue:@"1234" forKey:@"password"];
[request addPostValue:@"ebay" forKey:@"directory"];
[request setData:imageData withFileName:@"images.jpg" andContentType:@"image/jpg" forKey:@"filename"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
}
Upvotes: 0
Views: 226
Reputation: 45180
I'm not sure whether it's a code fault, since there is no crash and you receive a response. {"success":"false", "message":"Authentication Failed"}
means that there is something wrong with the authentication. Check if there is any login/password/acces key required to upload your file and if yes, implement it.
Upvotes: 2