Declared in AFURLRequestSerialization.h

Overview

The AFMultipartFormData protocol defines the methods supported by the parameter in the block argument of AFHTTPRequestSerializer -multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:.

Instance Methods

appendPartWithFileData:name:fileName:mimeType:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the encoded file data and the multipart form boundary.

- (void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType

Parameters

data

The data to be encoded and appended to the form data.

name

The name to be associated with the specified data. This parameter must not be nil.

fileName

The filename to be associated with the specified data. This parameter must not be nil.

mimeType

The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

appendPartWithFileURL:name:error:

Appends the HTTP header Content-Disposition: file; filename=#{generated filename}; name=#{name}" and Content-Type: #{generated mimeType}, followed by the encoded file data and the multipart form boundary.

- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError *__autoreleasing *)error

Parameters

fileURL

The URL corresponding to the file whose content will be appended to the form. This parameter must not be nil.

name

The name to be associated with the specified data. This parameter must not be nil.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Return Value

YES if the file data was successfully appended, otherwise NO.

Discussion

The filename and MIME type for this data in the form will be automatically generated, using the last path component of the fileURL and system associated MIME type for the fileURL extension, respectively.

Declared In

AFURLRequestSerialization.h

appendPartWithFileURL:name:fileName:mimeType:error:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the encoded file data and the multipart form boundary.

- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType error:(NSError *__autoreleasing *)error

Parameters

fileURL

The URL corresponding to the file whose content will be appended to the form. This parameter must not be nil.

name

The name to be associated with the specified data. This parameter must not be nil.

fileName

The file name to be used in the Content-Disposition header. This parameter must not be nil.

mimeType

The declared MIME type of the file data. This parameter must not be nil.

error

If an error occurs, upon return contains an NSError object that describes the problem.

Return Value

YES if the file data was successfully appended otherwise NO.

Declared In

AFURLRequestSerialization.h

appendPartWithFormData:name:

Appends the HTTP headers Content-Disposition: form-data; name=#{name}", followed by the encoded data and the multipart form boundary.

- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name

Parameters

data

The data to be encoded and appended to the form data.

name

The name to be associated with the specified data. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

appendPartWithHeaders:body:

Appends HTTP headers, followed by the encoded data and the multipart form boundary.

- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body

Parameters

headers

The HTTP headers to be appended to the form data.

body

The data to be encoded and appended to the form data.

Declared In

AFURLRequestSerialization.h

appendPartWithInputStream:name:fileName:length:mimeType:

Appends the HTTP header Content-Disposition: file; filename=#{filename}; name=#{name}" and Content-Type: #{mimeType}, followed by the data from the input stream and the multipart form boundary.

- (void)appendPartWithInputStream:(NSInputStream *)inputStream name:(NSString *)name fileName:(NSString *)fileName length:(NSUInteger)length mimeType:(NSString *)mimeType

Parameters

inputStream

The input stream to be appended to the form data

name

The name to be associated with the specified input stream. This parameter must not be nil.

fileName

The filename to be associated with the specified input stream. This parameter must not be nil.

length

The length of the specified input stream in bytes.

mimeType

The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be nil.

Declared In

AFURLRequestSerialization.h

throttleBandwidthWithPacketSize:delay:

Throttles request bandwidth by limiting the packet size and adding a delay for each chunk read from the upload stream.

- (void)throttleBandwidthWithPacketSize:(NSUInteger)numberOfBytes delay:(NSTimeInterval)delay

Parameters

numberOfBytes

Maximum packet size, in number of bytes. The default packet size for an input stream is 16kb.

delay

Duration of delay each time a packet is read. By default, no delay is set.

Discussion

When uploading over a 3G or EDGE connection, requests may fail with “request body stream exhausted”. Setting a maximum packet size and delay according to the recommended values (kAFUploadStream3GSuggestedPacketSize and kAFUploadStream3GSuggestedDelay) lowers the risk of the input stream exceeding its allocated bandwidth. Unfortunately, there is no definite way to distinguish between a 3G, EDGE, or LTE connection over NSURLConnection. As such, it is not recommended that you throttle bandwidth based solely on network reachability. Instead, you should consider checking for the “request body stream exhausted” in a failure block, and then retrying the request with throttled bandwidth.

Declared In

AFURLRequestSerialization.h