How to Upload Images Using AFNetworking directly from iPad app

拥有回忆 提交于 2019-12-23 12:13:45

问题


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


回答1:


try with this its work for me

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


来源:https://stackoverflow.com/questions/28716100/how-to-upload-images-using-afnetworking-directly-from-ipad-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!