[英]Upload a image on server iPhone
I am new to iPhone. 我是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 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"} 我使用以下方法上传文件,但控制台中的结果是: {“success”:“false”,“message”:“身份验证失败”}
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 . {"success":"false", "message":"Authentication Failed"}
意味着有一些错误的认证 。 Check if there is any login/password/acces key required to upload your file and if yes, implement it. 检查上传文件是否需要登录/密码/访问密钥,如果是,请执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.