Latest 0.1.5
Homepage https://github.com/1amageek/NSMutableURLRequestMultipart
License MIT
Platforms ios 7.0
Frameworks MobileCoreServices
Authors

NSMutableURLRequestMultipart is a category of NSMutableURLRequest for sending a simple POST request.

MultipartFormData

You create a form using the MultipartFormData.

- (void)appendValue:(NSString *)value name:(NSString *)name;
- (void)appendFileURL:(NSURL *)fileURL
                 name:(NSString *)name
                error:(NSError * __autoreleasing *)error;
- (void)appendFileData:(NSData *)data
                  name:(NSString *)name
              fileName:(NSString *)fileName
              mimeType:(NSString *)mimeType
                 error:(NSError * __autoreleasing *)error;

Usage

    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];

    UIImage *image = [UIImage imageNamed:@"Lenna"];
    NSData *data = UIImageJPEGRepresentation(image, 1);

    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithMultipartFormRequestWithURL:[NSURL URLWithString:@"http://localhost:3000/media/upload"] constructingBodyWithBlock:^(MultipartFormData *formData) {
        [formData appendFileData:data name:@"fileName" mimeType:@"image/jpeg" error:nil];
    }];

    NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
      // response
    }];
    [task resume];

Latest podspec

{
    "name": "NSMutableURLRequestMultipart",
    "version": "0.1.5",
    "summary": "NSMutableURLRequestMultipart is a category of NSMutableURLRequest for sending a simple POST request.",
    "homepage": "https://github.com/1amageek/NSMutableURLRequestMultipart",
    "license": {
        "type": "MIT"
    },
    "authors": {
        "1_am_a_geek": "[email protected]"
    },
    "social_media_url": "http://twitter.com/1_am_a_geek",
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/1amageek/NSMutableURLRequestMultipart.git",
        "tag": "0.1.4"
    },
    "source_files": [
        "NSMutableURLRequestMultipart/**/*.{h,m}"
    ],
    "exclude_files": [
        "NSMutableURLRequestMultipart/AppDelegate.*",
        "NSMutableURLRequestMultipart/ViewController.*",
        "NSMutableURLRequestMultipart/main.m"
    ],
    "public_header_files": "NSMutableURLRequestMultipart/**/*.h",
    "frameworks": [
        "MobileCoreServices"
    ]
}

Pin It on Pinterest

Share This