如何上传图片到服务器(ios)

该上传使用的是第三方框架,至于框架的名字就不用多说了 

AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];

    mgr.requestSerializer= [AFHTTPRequestSerializer serializer];

    mgr.responseSerializer= [AFHTTPResponseSerializer serializer];

    NSDictionary *dic;//上传内容

    [mgr POST:@"" parameters:dic constructingBodyWithBlock:^(id<AFMultipartFormData_Nonnull formData) {

            NSData *data ;//上传图片

        [formData appendPartWithFileData:data name:@“” fileName:@“” mimeType:@"image/png"];    

    } success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {

        NSLog(@"%@",responseObject);

    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {

        NSLog(@"%@",error); 

    }];


你可能感兴趣的:(图片以及内容的上传)