2
0
Эх сурвалжийг харах

Merge pull request #334 from obohrer/convenience-fns-upload

Convenience upload functions in Manager
Mattt Thompson 10 жил өмнө
parent
commit
8b6484a5bf
1 өөрчлөгдсөн 45 нэмэгдсэн , 0 устгасан
  1. 45 0
      Source/Alamofire.swift

+ 45 - 0
Source/Alamofire.swift

@@ -1031,6 +1031,21 @@ extension Manager {
     public func upload(URLRequest: URLRequestConvertible, file: NSURL) -> Request {
         return upload(.File(URLRequest.URLRequest, file))
     }
+  
+    /**
+        Creates a request for uploading a file to the specified URL request.
+  
+        If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
+  
+        :param: method The HTTP method.
+        :param: URLString The URL string.
+        :param: file The file to upload
+  
+        :returns: The created upload request.
+    */
+    public func upload(method: Method, _ URLString: URLStringConvertible, file: NSURL) -> Request {
+        return upload(URLRequest(method, URLString), file: file)
+    }
 
     // MARK: Data
 
@@ -1047,6 +1062,21 @@ extension Manager {
     public func upload(URLRequest: URLRequestConvertible, data: NSData) -> Request {
         return upload(.Data(URLRequest.URLRequest, data))
     }
+  
+    /**
+        Creates a request for uploading data to the specified URL request.
+  
+        If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
+  
+        :param: method The HTTP method.
+        :param: URLString The URL string.
+        :param: data The data to upload
+  
+        :returns: The created upload request.
+    */
+    public func upload(method: Method, _ URLString: URLStringConvertible, data: NSData) -> Request {
+        return upload(URLRequest(method, URLString), data: data)
+    }
 
     // MARK: Stream
 
@@ -1063,6 +1093,21 @@ extension Manager {
     public func upload(URLRequest: URLRequestConvertible, stream: NSInputStream) -> Request {
         return upload(.Stream(URLRequest.URLRequest, stream))
     }
+  
+    /**
+        Creates a request for uploading a stream to the specified URL request.
+  
+        If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
+  
+        :param: method The HTTP method.
+        :param: URLString The URL string.
+        :param: stream The stream to upload.
+
+        :returns: The created upload request.
+    */
+    public func upload(method: Method, _ URLString: URLStringConvertible, stream: NSInputStream) -> Request {
+        return upload(URLRequest(method, URLString), stream: stream)
+    }
 }
 
 extension Request {