|
@@ -117,7 +117,7 @@ public class MultipartFormData {
|
|
|
/**
|
|
/**
|
|
|
Creates a multipart form data object.
|
|
Creates a multipart form data object.
|
|
|
|
|
|
|
|
- :returns: The multipart form data object.
|
|
|
|
|
|
|
+ - returns: The multipart form data object.
|
|
|
*/
|
|
*/
|
|
|
public init() {
|
|
public init() {
|
|
|
self.boundary = BoundaryGenerator.randomBoundary()
|
|
self.boundary = BoundaryGenerator.randomBoundary()
|
|
@@ -143,8 +143,8 @@ public class MultipartFormData {
|
|
|
- Encoded data
|
|
- Encoded data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: data The data to encode into the multipart form data.
|
|
|
|
|
- :param: name The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
|
|
+ - parameter data: The data to encode into the multipart form data.
|
|
|
|
|
+ - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(data data: NSData, name: String) {
|
|
public func appendBodyPart(data data: NSData, name: String) {
|
|
|
let headers = contentHeaders(name: name)
|
|
let headers = contentHeaders(name: name)
|
|
@@ -164,9 +164,9 @@ public class MultipartFormData {
|
|
|
- Encoded data
|
|
- Encoded data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: data The data to encode into the multipart form data.
|
|
|
|
|
- :param: name The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: mimeType The MIME type to associate with the data content type in the `Content-Type` HTTP header.
|
|
|
|
|
|
|
+ - parameter data: The data to encode into the multipart form data.
|
|
|
|
|
+ - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter mimeType: The MIME type to associate with the data content type in the `Content-Type` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(data data: NSData, name: String, mimeType: String) {
|
|
public func appendBodyPart(data data: NSData, name: String, mimeType: String) {
|
|
|
let headers = contentHeaders(name: name, mimeType: mimeType)
|
|
let headers = contentHeaders(name: name, mimeType: mimeType)
|
|
@@ -186,10 +186,10 @@ public class MultipartFormData {
|
|
|
- Encoded file data
|
|
- Encoded file data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: data The data to encode into the multipart form data.
|
|
|
|
|
- :param: name The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: fileName The filename to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: mimeType The MIME type to associate with the data in the `Content-Type` HTTP header.
|
|
|
|
|
|
|
+ - parameter data: The data to encode into the multipart form data.
|
|
|
|
|
+ - parameter name: The name to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter fileName: The filename to associate with the data in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter mimeType: The MIME type to associate with the data in the `Content-Type` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) {
|
|
public func appendBodyPart(data data: NSData, name: String, fileName: String, mimeType: String) {
|
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
@@ -213,8 +213,8 @@ public class MultipartFormData {
|
|
|
`fileURL`. The `Content-Type` HTTP header MIME type is generated by mapping the `fileURL` extension to the
|
|
`fileURL`. The `Content-Type` HTTP header MIME type is generated by mapping the `fileURL` extension to the
|
|
|
system associated MIME type.
|
|
system associated MIME type.
|
|
|
|
|
|
|
|
- :param: fileURL The URL of the file whose content will be encoded into the multipart form data.
|
|
|
|
|
- :param: name The name to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
|
|
|
|
+ - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data.
|
|
|
|
|
+ - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(fileURL fileURL: NSURL, name: String) {
|
|
public func appendBodyPart(fileURL fileURL: NSURL, name: String) {
|
|
|
if let
|
|
if let
|
|
@@ -242,10 +242,10 @@ public class MultipartFormData {
|
|
|
- Encoded file data
|
|
- Encoded file data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: fileURL The URL of the file whose content will be encoded into the multipart form data.
|
|
|
|
|
- :param: name The name to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: fileName The filename to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: mimeType The MIME type to associate with the file content in the `Content-Type` HTTP header.
|
|
|
|
|
|
|
+ - parameter fileURL: The URL of the file whose content will be encoded into the multipart form data.
|
|
|
|
|
+ - parameter name: The name to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter fileName: The filename to associate with the file content in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter mimeType: The MIME type to associate with the file content in the `Content-Type` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) {
|
|
public func appendBodyPart(fileURL fileURL: NSURL, name: String, fileName: String, mimeType: String) {
|
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
@@ -344,11 +344,11 @@ public class MultipartFormData {
|
|
|
- Encoded stream data
|
|
- Encoded stream data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: stream The input stream to encode in the multipart form data.
|
|
|
|
|
- :param: length The content length of the stream.
|
|
|
|
|
- :param: name The name to associate with the stream content in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: fileName The filename to associate with the stream content in the `Content-Disposition` HTTP header.
|
|
|
|
|
- :param: mimeType The MIME type to associate with the stream content in the `Content-Type` HTTP header.
|
|
|
|
|
|
|
+ - parameter stream: The input stream to encode in the multipart form data.
|
|
|
|
|
+ - parameter length: The content length of the stream.
|
|
|
|
|
+ - parameter name: The name to associate with the stream content in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter fileName: The filename to associate with the stream content in the `Content-Disposition` HTTP header.
|
|
|
|
|
+ - parameter mimeType: The MIME type to associate with the stream content in the `Content-Type` HTTP header.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) {
|
|
public func appendBodyPart(stream stream: NSInputStream, length: UInt64, name: String, fileName: String, mimeType: String) {
|
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
let headers = contentHeaders(name: name, fileName: fileName, mimeType: mimeType)
|
|
@@ -364,9 +364,9 @@ public class MultipartFormData {
|
|
|
- Encoded stream data
|
|
- Encoded stream data
|
|
|
- Multipart form boundary
|
|
- Multipart form boundary
|
|
|
|
|
|
|
|
- :param: stream The input stream to encode in the multipart form data.
|
|
|
|
|
- :param: length The content length of the stream.
|
|
|
|
|
- :param: headers The HTTP headers for the body part.
|
|
|
|
|
|
|
+ - parameter stream: The input stream to encode in the multipart form data.
|
|
|
|
|
+ - parameter length: The content length of the stream.
|
|
|
|
|
+ - parameter headers: The HTTP headers for the body part.
|
|
|
*/
|
|
*/
|
|
|
public func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) {
|
|
public func appendBodyPart(stream stream: NSInputStream, length: UInt64, headers: [String: String]) {
|
|
|
let bodyPart = BodyPart(headers: headers, bodyStream: stream, bodyContentLength: length)
|
|
let bodyPart = BodyPart(headers: headers, bodyStream: stream, bodyContentLength: length)
|
|
@@ -382,7 +382,7 @@ public class MultipartFormData {
|
|
|
time. This method should only be used when the encoded data will have a small memory footprint. For large data
|
|
time. This method should only be used when the encoded data will have a small memory footprint. For large data
|
|
|
cases, please use the `writeEncodedDataToDisk(fileURL:completionHandler:)` method.
|
|
cases, please use the `writeEncodedDataToDisk(fileURL:completionHandler:)` method.
|
|
|
|
|
|
|
|
- :returns: EncodingResult containing an `NSData` object if the encoding succeeded, an `NSError` otherwise.
|
|
|
|
|
|
|
+ - returns: EncodingResult containing an `NSData` object if the encoding succeeded, an `NSError` otherwise.
|
|
|
*/
|
|
*/
|
|
|
public func encode() -> EncodingResult {
|
|
public func encode() -> EncodingResult {
|
|
|
if let bodyPartError = bodyPartError {
|
|
if let bodyPartError = bodyPartError {
|
|
@@ -415,8 +415,8 @@ public class MultipartFormData {
|
|
|
This process is facilitated by reading and writing with input and output streams, respectively. Thus,
|
|
This process is facilitated by reading and writing with input and output streams, respectively. Thus,
|
|
|
this approach is very memory efficient and should be used for large body part data.
|
|
this approach is very memory efficient and should be used for large body part data.
|
|
|
|
|
|
|
|
- :param: fileURL The file URL to write the multipart form data into.
|
|
|
|
|
- :param: completionHandler A closure to be executed when writing is finished.
|
|
|
|
|
|
|
+ - parameter fileURL: The file URL to write the multipart form data into.
|
|
|
|
|
+ - parameter completionHandler: A closure to be executed when writing is finished.
|
|
|
*/
|
|
*/
|
|
|
public func writeEncodedDataToDisk(fileURL: NSURL, completionHandler: (NSError?) -> Void) {
|
|
public func writeEncodedDataToDisk(fileURL: NSURL, completionHandler: (NSError?) -> Void) {
|
|
|
if let bodyPartError = bodyPartError {
|
|
if let bodyPartError = bodyPartError {
|