Session
open class Session : @unchecked Sendable
extension Session: RequestDelegate
Session creates and manages Alamofire’s Request types during their lifetimes. It also provides common
functionality for all Requests, including queuing, interception, trust management, redirect handling, and response
cache handling.
-
Shared singleton instance used by all
AF.requestAPIs. Cannot be modified.Declaration
Swift
public static let `default`: Session -
Underlying
URLSessionused to createURLSessionTasksfor this instance, and for which this instance’sdelegatehandlesURLSessionDelegatecallbacks.Note
This instance should NOT be used to interact with the underlyingURLSessionTasks. Doing so will break internal Alamofire logic that tracks those tasks.Declaration
Swift
public let session: URLSession -
Instance’s
SessionDelegate, which handles theURLSessionDelegatemethods andRequestinteraction.Declaration
Swift
public let delegate: SessionDelegate -
Root
DispatchQueuefor all internal callbacks and state update. MUST be a serial queue.Declaration
Swift
public let rootQueue: DispatchQueue -
Value determining whether this instance automatically calls
resume()on all createdRequests.Declaration
Swift
public let startRequestsImmediately: Bool -
DispatchQueueon whichURLRequests are created asynchronously. By default this queue usesrootQueueas itstarget, but a separate queue can be used if request creation is determined to be a bottleneck. Always profile and test before introducing an additional queue.Declaration
Swift
public let requestQueue: DispatchQueue -
DispatchQueuepassed to allRequests on which they perform their response serialization. By default this queue usesrootQueueas itstargetbut a separate queue can be used if response serialization is determined to be a bottleneck. Always profile and test before introducing an additional queue.Declaration
Swift
public let serializationQueue: DispatchQueue -
RequestInterceptorused for allRequestcreated by the instance.RequestInterceptors can also be set on a per-Requestbasis, in which case theRequest‘s interceptor takes precedence over this value.Declaration
Swift
public let interceptor: (any RequestInterceptor)? -
ServerTrustManagerinstance used to evaluate all trust challenges and provide certificate and key pinning.Declaration
Swift
public let serverTrustManager: ServerTrustManager? -
RedirectHandlerinstance used to provide customization for request redirection.Declaration
Swift
public let redirectHandler: (any RedirectHandler)? -
CachedResponseHandlerinstance used to provide customization of cached response handling.Declaration
Swift
public let cachedResponseHandler: (any CachedResponseHandler)? -
CompositeEventMonitorused to compose any passedEventMonitors.Declaration
Swift
public let eventMonitor: CompositeEventMonitor -
EventMonitors included in all instances unless overwritten.[AlamofireNotifications()]by default.Declaration
Swift
@available(*, deprecated, message: "Use [AlamofireNotifications(﹚] directly.") public let defaultEventMonitors: [any EventMonitor] -
init(session:delegate: rootQueue: startRequestsImmediately: requestQueue: serializationQueue: interceptor: serverTrustManager: redirectHandler: cachedResponseHandler: eventMonitors: ) Creates a
Sessionfrom aURLSessionand other parameters.Note
When passing a
URLSession, you must create theURLSessionwith a specificdelegateQueuevalue and pass thedelegateQueue‘sunderlyingQueueas therootQueueparameter of this initializer.Declaration
Swift
public init(session: URLSession, delegate: SessionDelegate, rootQueue: DispatchQueue, startRequestsImmediately: Bool = true, requestQueue: DispatchQueue? = nil, serializationQueue: DispatchQueue? = nil, interceptor: (any RequestInterceptor)? = nil, serverTrustManager: ServerTrustManager? = nil, redirectHandler: (any RedirectHandler)? = nil, cachedResponseHandler: (any CachedResponseHandler)? = nil, eventMonitors: [any EventMonitor] = [AlamofireNotifications()])Parameters
sessionUnderlying
URLSessionfor this instance.delegateSessionDelegatethat handlessession‘s delegate callbacks as well asRequestinteraction.rootQueueRoot
DispatchQueuefor all internal callbacks and state updates. MUST be a serial queue.startRequestsImmediatelyrequestQueueDispatchQueueon which to performURLRequestcreation. By default this queue will use therootQueueas itstarget. A separate queue can be used if it’s determined request creation is a bottleneck, but that should only be done after careful testing and profiling.nilby default.serializationQueueDispatchQueueon which to perform all response serialization. By default this queue will use therootQueueas itstarget. A separate queue can be used if it’s determined response serialization is a bottleneck, but that should only be done after careful testing and profiling.nilby default.interceptorRequestInterceptorto be used for allRequests created by this instance.nilby default.serverTrustManagerServerTrustManagerto be used for all trust evaluations by this instance.nilby default.redirectHandlerRedirectHandlerto be used by allRequests created by this instance.nilby default.cachedResponseHandlerCachedResponseHandlerto be used by allRequests created by this instance.nilby default.eventMonitorsEventMonitors used by the instance.[AlamofireNotifications()]by default. -
init(configuration:delegate: rootQueue: startRequestsImmediately: requestQueue: serializationQueue: interceptor: serverTrustManager: redirectHandler: cachedResponseHandler: eventMonitors: ) Creates a
Sessionfrom aURLSessionConfiguration.Note
This initializer lets Alamofire handle the creation of the underlying
URLSessionand itsdelegateQueue, and is the recommended initializer for most uses.Declaration
Swift
public convenience init(configuration: URLSessionConfiguration = URLSessionConfiguration.af.default, delegate: SessionDelegate = SessionDelegate(), rootQueue: DispatchQueue = DispatchQueue(label: "org.alamofire.session.rootQueue"), startRequestsImmediately: Bool = true, requestQueue: DispatchQueue? = nil, serializationQueue: DispatchQueue? = nil, interceptor: (any RequestInterceptor)? = nil, serverTrustManager: ServerTrustManager? = nil, redirectHandler: (any RedirectHandler)? = nil, cachedResponseHandler: (any CachedResponseHandler)? = nil, eventMonitors: [any EventMonitor] = [AlamofireNotifications()])Parameters
configurationURLSessionConfigurationto be used to create the underlyingURLSession. Changes to this value after being passed to this initializer will have no effect.URLSessionConfiguration.af.defaultby default.delegateSessionDelegatethat handlessession‘s delegate callbacks as well asRequestinteraction.SessionDelegate()by default.rootQueueRoot
DispatchQueuefor all internal callbacks and state updates. MUST be a serial queue.DispatchQueue(label: "org.alamofire.session.rootQueue")by default.startRequestsImmediatelyrequestQueueDispatchQueueon which to performURLRequestcreation. By default this queue will use therootQueueas itstarget. A separate queue can be used if it’s determined request creation is a bottleneck, but that should only be done after careful testing and profiling.nilby default.serializationQueueDispatchQueueon which to perform all response serialization. By default this queue will use therootQueueas itstarget. A separate queue can be used if it’s determined response serialization is a bottleneck, but that should only be done after careful testing and profiling.nilby default.interceptorRequestInterceptorto be used for allRequests created by this instance.nilby default.serverTrustManagerServerTrustManagerto be used for all trust evaluations by this instance.nilby default.redirectHandlerRedirectHandlerto be used by allRequests created by this instance.nilby default.cachedResponseHandlerCachedResponseHandlerto be used by allRequests created by this instance.nilby default.eventMonitorsEventMonitors used by the instance.[AlamofireNotifications()]by default.
-
Perform an action on all active
Requests.Note
The provided
actionclosure is performed asynchronously, meaning that someRequests may complete and be unavailable by time it runs. Additionally, this action is performed on the instances’srootQueue, so care should be taken that actions are fast. Once the work on theRequests is complete, any additional work should be performed on another queue.Declaration
Swift
public func withAllRequests(perform action: @escaping @Sendable (Set<Request>) -> Void)Parameters
actionClosure to perform with all
Requests. -
Cancel all active
Requests, optionally calling a completion handler when complete.Declaration
Swift
public func cancelAllRequests(completingOnQueue queue: DispatchQueue = .main, completion: (@Sendable () -> Void)? = nil)Parameters
queueDispatchQueueon which the completion handler is run..mainby default.completionClosure to be called when all
Requests have been cancelled.
-
Closure which provides a
URLRequestfor mutation.Declaration
Swift
public typealias RequestModifier = @Sendable (inout URLRequest) throws -> Void -
Creates a
DataRequestfrom aURLRequestcreated using the passed components and aRequestInterceptor.Declaration
Swift
open func request(_ convertible: any URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: any ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil) -> DataRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.parametersParameters(a.k.a.[String: Any]) value to be encoded into theURLRequest.nilby default.encodingParameterEncodingto be used to encode theparametersvalue into theURLRequest.URLEncoding.defaultby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
DataRequest. -
Creates a
DataRequestfrom aURLRequestcreated using the passed components,Encodableparameters, and aRequestInterceptor.Declaration
Swift
open func request<Parameters: Encodable & Sendable>(_ convertible: any URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil) -> DataRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.parametersEncodablevalue to be encoded into theURLRequest.nilby default.encoderParameterEncoderto be used to encode theparametersvalue into theURLRequest.URLEncodedFormParameterEncoder.defaultby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
DataRequest. -
Creates a
DataRequestfrom aURLRequestConvertiblevalue and aRequestInterceptor.Declaration
Swift
open func request(_ convertible: any URLRequestConvertible, interceptor: (any RequestInterceptor)? = nil) -> DataRequestParameters
convertibleURLRequestConvertiblevalue to be used to create theURLRequest.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.Return Value
The created
DataRequest.
-
streamRequest(_:method: parameters: encoder: headers: automaticallyCancelOnStreamError: interceptor: requestModifier: ) Creates a
DataStreamRequestfrom the passed components,Encodableparameters, andRequestInterceptor.Declaration
Swift
open func streamRequest<Parameters: Encodable & Sendable>(_ convertible: any URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, automaticallyCancelOnStreamError: Bool = false, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil) -> DataStreamRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.parametersEncodablevalue to be encoded into theURLRequest.nilby default.encoderParameterEncoderto be used to encode theparametersvalue into theURLRequest.URLEncodedFormParameterEncoder.defaultby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.automaticallyCancelOnStreamErrorBoolindicating whether the instance should be canceled when anErroris thrown while serializing streamData.falseby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
DataStreamrequest. -
Creates a
DataStreamRequestfrom the passed components andRequestInterceptor.Declaration
Swift
open func streamRequest(_ convertible: any URLConvertible, method: HTTPMethod = .get, headers: HTTPHeaders? = nil, automaticallyCancelOnStreamError: Bool = false, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil) -> DataStreamRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.automaticallyCancelOnStreamErrorBoolindicating whether the instance should be canceled when anErroris thrown while serializing streamData.falseby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
DataStreamrequest. -
Creates a
DataStreamRequestfrom the passedURLRequestConvertiblevalue andRequestInterceptor.Declaration
Swift
open func streamRequest(_ convertible: any URLRequestConvertible, automaticallyCancelOnStreamError: Bool = false, interceptor: (any RequestInterceptor)? = nil) -> DataStreamRequestParameters
convertibleURLRequestConvertiblevalue to be used to create theURLRequest.automaticallyCancelOnStreamErrorBoolindicating whether the instance should be canceled when anErroris thrown while serializing streamData.falseby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.Return Value
The created
DataStreamRequest.
-
Creates a
DownloadRequestusing aURLRequestcreated using the passed components,RequestInterceptor, andDestination.Declaration
Swift
open func download(_ convertible: any URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: any ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.parametersParameters(a.k.a.[String: Any]) value to be encoded into theURLRequest.nilby default.encodingParameterEncodingto be used to encode theparametersvalue into theURLRequest. Defaults toURLEncoding.default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.destinationDownloadRequest.Destinationclosure used to determine how and where the downloaded file should be moved.nilby default.Return Value
The created
DownloadRequest. -
Creates a
DownloadRequestfrom aURLRequestcreated using the passed components,Encodableparameters, and aRequestInterceptor.Declaration
Swift
open func download<Parameters: Encodable & Sendable>(_ convertible: any URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, requestModifier: RequestModifier? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..getby default.parametersValue conforming to
Encodableto be encoded into theURLRequest.nilby default.encoderParameterEncoderto be used to encode theparametersvalue into theURLRequest. Defaults toURLEncodedFormParameterEncoder.default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.destinationDownloadRequest.Destinationclosure used to determine how and where the downloaded file should be moved.nilby default.Return Value
The created
DownloadRequest. -
Creates a
DownloadRequestfrom aURLRequestConvertiblevalue, aRequestInterceptor, and aDestination.Declaration
Swift
open func download(_ convertible: any URLRequestConvertible, interceptor: (any RequestInterceptor)? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
convertibleURLRequestConvertiblevalue to be used to create theURLRequest.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.destinationDownloadRequest.Destinationclosure used to determine how and where the downloaded file should be moved.nilby default.Return Value
The created
DownloadRequest. -
Creates a
DownloadRequestfrom theresumeDataproduced from a previously cancelledDownloadRequest, as well as aRequestInterceptor, and aDestination.Note
If
destinationis not specified, the download will be moved to a temporary location determined by Alamofire. The file will not be deleted until the system purges the temporary files.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),
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
open func download(resumingWith data: Data, interceptor: (any RequestInterceptor)? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequestParameters
dataThe resume data from a previously cancelled
DownloadRequestorURLSessionDownloadTask.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.destinationDownloadRequest.Destinationclosure used to determine how and where the downloaded file should be moved.nilby default.Return Value
The created
DownloadRequest.
-
Creates an
UploadRequestfor the givenData,URLRequestcomponents, andRequestInterceptor.Declaration
Swift
open func upload(_ data: Data, to convertible: any URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default, requestModifier: RequestModifier? = nil) -> UploadRequestParameters
dataThe
Datato upload.convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..postby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestfor the givenDatausing theURLRequestConvertiblevalue andRequestInterceptor.Declaration
Swift
open func upload(_ data: Data, with convertible: any URLRequestConvertible, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default) -> UploadRequestParameters
dataThe
Datato upload.convertibleURLRequestConvertiblevalue to be used to create theURLRequest.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.Return Value
The created
UploadRequest.
-
Creates an
UploadRequestfor the file at the given fileURL, using aURLRequestfrom the provided components andRequestInterceptor.Declaration
Swift
open func upload(_ fileURL: URL, to convertible: any URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default, requestModifier: RequestModifier? = nil) -> UploadRequestParameters
fileURLThe
URLof the file to upload.convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..postby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedUploadRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestfor the file at the given fileURLusing theURLRequestConvertiblevalue andRequestInterceptor.Declaration
Swift
open func upload(_ fileURL: URL, with convertible: any URLRequestConvertible, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default) -> UploadRequestParameters
fileURLThe
URLof the file to upload.convertibleURLRequestConvertiblevalue to be used to create theURLRequest.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.Return Value
The created
UploadRequest.
-
Creates an
UploadRequestfrom theInputStreamprovided using aURLRequestfrom the provided components andRequestInterceptor.Declaration
Swift
open func upload(_ stream: InputStream, to convertible: any URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default, requestModifier: RequestModifier? = nil) -> UploadRequestParameters
streamThe
InputStreamthat provides the data to upload.convertibleURLConvertiblevalue to be used as theURLRequest‘sURL.methodHTTPMethodfor theURLRequest..postby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestfrom the providedInputStreamusing theURLRequestConvertiblevalue andRequestInterceptor.Declaration
Swift
open func upload(_ stream: InputStream, with convertible: any URLRequestConvertible, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default) -> UploadRequestParameters
streamThe
InputStreamthat provides the data to upload.convertibleURLRequestConvertiblevalue to be used to create theURLRequest.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.Return Value
The created
UploadRequest.
-
Creates an
UploadRequestfor the multipart form data built using a closure and sent using the providedURLRequestcomponents andRequestInterceptor.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
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
open func upload(multipartFormData: @escaping (MultipartFormData) -> Void, to url: any URLConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default, requestModifier: RequestModifier? = nil) -> UploadRequestParameters
multipartFormDataMultipartFormDatabuilding closure.urlURLConvertiblevalue to be used as theURLRequest‘sURL.encodingMemoryThresholdByte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default.methodHTTPMethodfor theURLRequest..postby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestusing aMultipartFormDatabuilding closure, the providedURLRequestConvertiblevalue, and aRequestInterceptor.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
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
open func upload(multipartFormData: @escaping (MultipartFormData) -> Void, with request: any URLRequestConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default) -> UploadRequestParameters
multipartFormDataMultipartFormDatabuilding closure.requestURLRequestConvertiblevalue to be used to create theURLRequest.encodingMemoryThresholdByte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestfor the prebuiltMultipartFormDatavalue using the providedURLRequestcomponents andRequestInterceptor.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
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
open func upload(multipartFormData: MultipartFormData, to url: any URLConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default, requestModifier: RequestModifier? = nil) -> UploadRequestParameters
multipartFormDataMultipartFormDatainstance to upload.urlURLConvertiblevalue to be used as theURLRequest‘sURL.encodingMemoryThresholdByte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default.methodHTTPMethodfor theURLRequest..postby default.headersHTTPHeadersvalue to be added to theURLRequest.nilby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.requestModifierRequestModifierwhich will be applied to theURLRequestcreated from the provided parameters.nilby default.Return Value
The created
UploadRequest. -
Creates an
UploadRequestfor the prebuiltMultipartFormDatavalue using the providingURLRequestConvertiblevalue andRequestInterceptor.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
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
open func upload(multipartFormData: MultipartFormData, with request: any URLRequestConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, interceptor: (any RequestInterceptor)? = nil, fileManager: FileManager = .default) -> UploadRequestParameters
multipartFormDataMultipartFormDatainstance to upload.requestURLRequestConvertiblevalue to be used to create theURLRequest.encodingMemoryThresholdByte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default.interceptorRequestInterceptorvalue to be used by the returnedDataRequest.nilby default.fileManagerFileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.Return Value
The created
UploadRequest.
-
Declaration
Swift
public var sessionConfiguration: URLSessionConfiguration { get } -
Declaration
Swift
public var startImmediately: Bool { get } -
Declaration
Swift
public func cleanup(after request: Request) -
Declaration
Swift
public func retryResult(for request: Request, dueTo error: AFError, completion: @escaping @Sendable (RetryResult) -> Void) -
Declaration
Swift
public func retryRequest(_ request: Request, withDelay timeDelay: TimeInterval?)
View on GitHub
Install in Dash