简体   繁体   中英

Upload a image on server iPhone

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];



}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM