如何直接从iPad应用程序使用AFNetworking上传图像 [英] How to Upload Images Using AFNetworking directly from iPad app

查看:92
本文介绍了如何直接从iPad应用程序使用AFNetworking上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS新手。我想使用 AFNetworking 将图片上传到我的服务器。
我试了但是还没有完成。请帮助我,提前谢谢

I am totally new to iOS.I want to upload images to my server using AFNetworking. I tried it but it still not done. Please Help me, thanks in advance

推荐答案

尝试使用它为我工作

-(void) uplodeImages{

    AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager   alloc] initWithBaseURL:[NSURL URLWithString:@"url where to upload images"]];
    NSData *imageData = UIImagePNGRepresentation([UIImage    imageNamed:@"cat1.png"]);
    NSDictionary *parameters = @{@"username": @"", @"password" : @""};
    AFHTTPRequestOperation *op = [manager POST:@"cat1.png" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        //do not put image inside parameters dictionary as I did, but append it!
        [formData appendPartWithFileData:imageData name:@"userfile" fileName:@"cat1.png" mimeType:@"image/png"];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success: %@ ***** %@", operation.responseString, responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@ ***** %@", operation.responseString, error);
    }];
    [op start];
}

这篇关于如何直接从iPad应用程序使用AFNetworking上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆