【问题标题】:Upload a image on server iPhone在服务器 iPhone 上上传图像
【发布时间】:2012-07-20 12:19:13
【问题描述】:

我是 iPhone 新手。我想将图像上传到服务器。我有网址

http://lifestander.com:8080/fileupload/uploadfile.html?username=tom&password=1234&directory=ebay&filename=fantacy.jpg

我用下面的方法上传文件,但是控制台的结果是:{"success":"false", "message":"Authentication Failed"}

我不明白控制台中的输出。所以请告诉我我做错了什么,或者改进我的代码。怎么办?

谢谢。

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



}

【问题讨论】:

    标签: iphone ios web-services


    【解决方案1】:

    我不确定这是否是代码错误,因为没有崩溃并且您会收到响应。 {"success":"false", "message":"Authentication Failed"} 表示authentication 有问题。检查上传文件是否需要任何登录/密码/访问密钥,如果是,请实施。

    【讨论】:

    • 感谢您的快速回复。我想问我做得对吗?
    • 您的代码是正确的,我正在以类似的方式使用 ASIFormDataRequest。错误必须在这里:[request addPostValue:@"tom" forKey:@"username"]; [request addPostValue:@"1234" forKey:@"password"];。您确定这是正确的登录数据吗?
    • 是的。用户名和密码正确。请查看我在 NSString *photoUploadURLString 中使用的 url。这是正确的还是我使用完整的网址?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 2016-03-21
    相关资源
    最近更新 更多