-
Creates a
DataRequestusingSessionManager.defaultto retrive the contents of the specifiedurlusing themethod,parameters,encoding, andheadersprovided.Declaration
Swift
public static func request(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil) -> DataRequestParameters
urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.getby default.parametersThe
Parameters,nilby default.encodingThe
ParameterEncoding,URLEncoding.defaultby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
DataRequest. -
Creates a
DataRequestusingSessionManager.defaultto retrive the contents of the specifiedurlusing themethod,parameters,encoding, andheadersprovided.Declaration
Swift
public static func request<Parameters: Encodable>(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil) -> DataRequestParameters
urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.getby default.parametersThe
Encodableparameters,nilby default.encodingThe
ParameterEncoding,URLEncodedFormParameterEncoder.defaultby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
DataRequest. -
Creates a
DataRequestusingSessionManager.defaultto execute the specifiedurlRequest.Declaration
Swift
public static func request(_ urlRequest: URLRequestConvertible) -> DataRequestParameters
urlRequestThe
URLRequestConvertiblevalue.Return Value
The created
DataRequest.
-
Creates a
DownloadRequestusingSessionManager.defaultto download the contents of the specifiedurlto the provideddestinationusing themethod,parameters,encoding, andheadersprovided.If
destinationis not specified, the download will remain at the temporary location determined by the underlyingURLSession.Declaration
Swift
public static func download(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.getby default.parametersThe
Parameters,nilby default.encodingThe
ParameterEncoding,URLEncoding.defaultby default.headersThe
HTTPHeaders,nilby default.destinationThe
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.Return Value
The created
DownloadRequest. -
Creates a
DownloadRequestusingSessionManager.defaultto download the contents of the specifiedurlto the provideddestinationusing themethod, encodableparameters,encoder, andheadersprovided.If
destinationis not specified, the download will remain at the temporary location determined by the underlyingURLSession.Declaration
Swift
public static func download<Parameters: Encodable>(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.getby default.parametersThe
Encodableparameters,nilby default.encoderThe
ParameterEncoder,URLEncodedFormParameterEncoder.defaultby default.headersThe
HTTPHeaders,nilby default.destinationThe
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.Return Value
The created
DownloadRequest.
-
Creates a
DownloadRequestusingSessionManager.defaultto execute the specifiedurlRequestand download the result to the provideddestination.Declaration
Swift
public static func download(_ urlRequest: URLRequestConvertible, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
urlRequestThe
URLRequestConvertiblevalue.destinationThe
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.Return Value
The created
DownloadRequest.
-
Creates a
DownloadRequestusing theSessionManager.defaultfrom theresumeDataproduced from a previousDownloadRequestcancellation to retrieve the contents of the original request and save them to thedestination.If
destinationis not specified, the contents will remain in the temporary location determined by the underlying URL session.On some versions of all Apple platforms (iOS 10 - 10.2, macOS 10.12 - 10.12.2, tvOS 10 - 10.1, watchOS 3 - 3.1.1),
resumeDatais broken on background URL session configurations. There’s an underlying bug in theresumeDatageneration logic where the data is written incorrectly and will always fail to resume the download. For more information about the bug and possible workarounds, please refer to the this Stack Overflow post.Declaration
Swift
public static func download(resumingWith resumeData: Data, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
resumeDataThe resume
Data. This is an opaque blob produced byURLSessionDownloadTaskwhen a task is cancelled. See Apple’s documentation for more information.destinationThe
DownloadRequest.Destinationclosure used to determine the destination of the downloaded file.nilby default.Return Value
The created
DownloadRequest.
-
Creates an
UploadRequestusingSessionManager.defaultto upload the contents of thefileURLspecified using theurl,methodandheadersprovided.Declaration
Swift
public static func upload(_ fileURL: URL, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> UploadRequestParameters
fileURLThe
URLof the file to upload.urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.postby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestusing theSessionManager.defaultto upload the contents of thefileURLspecificed using theurlRequestprovided.Declaration
Swift
public static func upload(_ fileURL: URL, with urlRequest: URLRequestConvertible) -> UploadRequestParameters
fileURLThe
URLof the file to upload.urlRequestThe
URLRequestConvertiblevalue.Return Value
The created
UploadRequest.
-
Creates an
UploadRequestusingSessionManager.defaultto upload the contents of thedataspecified using theurl,methodandheadersprovided.Declaration
Swift
public static func upload(_ data: Data, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> UploadRequestParameters
dataThe
Datato upload.urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.postby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestusingSessionManager.defaultto upload the contents of thedataspecified using theurlRequestprovided.Declaration
Swift
public static func upload(_ data: Data, with urlRequest: URLRequestConvertible) -> UploadRequestParameters
dataThe
Datato upload.urlRequestThe
URLRequestConvertiblevalue.Return Value
The created
UploadRequest.
-
Creates an
UploadRequestusingSessionManager.defaultto upload the content provided by thestreamspecified using theurl,methodandheadersprovided.Declaration
Swift
public static func upload(_ stream: InputStream, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> UploadRequestParameters
streamThe
InputStreamto upload.urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.postby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestusingSessionManager.defaultto upload the content provided by thestreamspecified using theurlRequestspecified.Declaration
Swift
public static func upload(_ stream: InputStream, with urlRequest: URLRequestConvertible) -> UploadRequestParameters
streamThe
InputStreamto upload.urlRequestThe
URLRequestConvertiblevalue.Return Value
The created
UploadRequest.
-
Encodes
multipartFormDatausingencodingMemoryThresholdand uploads the result usingSessionManager.defaultwith theurl,method, andheadersprovided.It is important to understand the memory implications of uploading
MultipartFormData. If the cummulative payload is small, encoding the data in-memory and directly uploading to a server is the by far the most efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be used for larger payloads such as video content.The
encodingMemoryThresholdparameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of theMultipartFormDatais below theencodingMemoryThreshold, encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding technique was used.Declaration
Swift
public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil) -> UploadRequestParameters
multipartFormDataThe closure used to append body parts to the
MultipartFormData.encodingMemoryThresholdThe encoding memory threshold in bytes.
10_000_000bytes by default.urlThe
URLConvertiblevalue.methodThe
HTTPMethod,.postby default.headersThe
HTTPHeaders,nilby default.Return Value
The created
UploadRequest. -
Encodes
multipartFormDatausingencodingMemoryThresholdand uploads the result usingSessionManager.defaultusing theurlRequestprovided.It is important to understand the memory implications of uploading
MultipartFormData. If the cummulative payload is small, encoding the data in-memory and directly uploading to a server is the by far the most efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be used for larger payloads such as video content.The
encodingMemoryThresholdparameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of theMultipartFormDatais below theencodingMemoryThreshold, encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding technique was used.Declaration
Swift
@discardableResult public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold, with urlRequest: URLRequestConvertible) -> UploadRequestParameters
multipartFormDataThe closure used to append body parts to the
MultipartFormData.encodingMemoryThresholdThe encoding memory threshold in bytes.
10_000_000bytes by default.urlRequestThe
URLRequestConvertiblevalue.Return Value
The
UploadRequestcreated.
View on GitHub
Install in Dash
AF Enumeration Reference