AF

public enum AF

Global namespace containing API for the default Session instance.

  • Creates a DownloadRequest using the Session.default from the resumeData produced from a previous DownloadRequest cancellation to retrieve the contents of the original request and save them to the destination.

    Note

    If destination is not specified, the download will be moved to a temporary location determined by Alamofire.

    Note

    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), resumeData is broken on background URL session configurations. There’s an underlying bug in the resumeData generation 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,
                                interceptor: RequestInterceptor? = nil,
                                to destination: DownloadRequest.Destination? = nil) -> DownloadRequest

    Parameters

    resumeData

    The resume Data. This is an opaque blob produced by URLSessionDownloadTask when a task is cancelled. See Apple’s documentation for more information.

    interceptor

    The RequestInterceptor, nil by default.

    destination

    The DownloadRequest.Destination closure used to determine the destination of the downloaded file. nil by default.

    Return Value

    The created DownloadRequest.

  • Creates an UploadRequest for the multipart form data built using a closure and sent using the provided URLRequest components and RequestInterceptor.

    It is important to understand the memory implications of uploading MultipartFormData. If the cumulative 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 encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold, 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,
                              to url: URLConvertible,
                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                              method: HTTPMethod = .post,
                              headers: HTTPHeaders? = nil,
                              interceptor: RequestInterceptor? = nil,
                              fileManager: FileManager = .default) -> UploadRequest

    Parameters

    multipartFormData

    MultipartFormData building closure.

    convertible

    URLConvertible value to be used as the URLRequest‘s URL.

    encodingMemoryThreshold

    Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded. MultipartFormData.encodingMemoryThreshold by default.

    method

    HTTPMethod for the URLRequest. .post by default.

    headers

    HTTPHeaders value to be added to the URLRequest. nil by default.

    interceptor

    RequestInterceptor value to be used by the returned DataRequest. nil by default.

    fileManager

    FileManager to be used if the form data exceeds the memory threshold and is written to disk before being uploaded. .default instance by default.

    Return Value

    The created UploadRequest.

  • Creates an UploadRequest using a MultipartFormData building closure, the provided URLRequestConvertible value, and a RequestInterceptor.

    It is important to understand the memory implications of uploading MultipartFormData. If the cumulative 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 encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold, 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,
                              with request: URLRequestConvertible,
                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                              interceptor: RequestInterceptor? = nil,
                              fileManager: FileManager = .default) -> UploadRequest

    Parameters

    multipartFormData

    MultipartFormData building closure.

    request

    URLRequestConvertible value to be used to create the URLRequest.

    encodingMemoryThreshold

    Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded. MultipartFormData.encodingMemoryThreshold by default.

    interceptor

    RequestInterceptor value to be used by the returned DataRequest. nil by default.

    fileManager

    FileManager to be used if the form data exceeds the memory threshold and is written to disk before being uploaded. .default instance by default.

    Return Value

    The created UploadRequest.

  • Creates an UploadRequest for the prebuilt MultipartFormData value using the provided URLRequest components and RequestInterceptor.

    It is important to understand the memory implications of uploading MultipartFormData. If the cumulative 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 encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold, 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: MultipartFormData,
                              to url: URLConvertible,
                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                              method: HTTPMethod = .post,
                              headers: HTTPHeaders? = nil,
                              interceptor: RequestInterceptor? = nil,
                              fileManager: FileManager = .default) -> UploadRequest

    Parameters

    multipartFormData

    MultipartFormData instance to upload.

    url

    URLConvertible value to be used as the URLRequest‘s URL.

    encodingMemoryThreshold

    Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded. MultipartFormData.encodingMemoryThreshold by default.

    method

    HTTPMethod for the URLRequest. .post by default.

    headers

    HTTPHeaders value to be added to the URLRequest. nil by default.

    interceptor

    RequestInterceptor value to be used by the returned DataRequest. nil by default.

    fileManager

    FileManager to be used if the form data exceeds the memory threshold and is written to disk before being uploaded. .default instance by default.

    Return Value

    The created UploadRequest.

  • Creates an UploadRequest for the prebuilt MultipartFormData value using the providing URLRequestConvertible value and RequestInterceptor.

    It is important to understand the memory implications of uploading MultipartFormData. If the cumulative 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 encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold, 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: MultipartFormData,
                              with request: URLRequestConvertible,
                              usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold,
                              interceptor: RequestInterceptor? = nil,
                              fileManager: FileManager = .default) -> UploadRequest

    Parameters

    multipartFormData

    MultipartFormData instance to upload.

    request

    URLRequestConvertible value to be used to create the URLRequest.

    encodingMemoryThreshold

    Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded. MultipartFormData.encodingMemoryThreshold by default.

    interceptor

    RequestInterceptor value to be used by the returned DataRequest. nil by default.

    fileManager

    FileManager instance to be used by the returned UploadRequest. .default instance by default.

    Return Value

    The created UploadRequest.