@@ -60,7 +60,8 @@ public class AlamofireWrapper: NSObject {
6060
6161 // MARK: - Request Methods
6262
63- @objc public func dataTaskWithHTTPMethodURLStringParametersHeadersUploadProgressDownloadProgressSuccessFailure(
63+ // Clean API: New shorter method name
64+ @objc public func request(
6465 _ method: String ,
6566 _ urlString: String ,
6667 _ parameters: NSDictionary ? ,
@@ -149,9 +150,9 @@ public class AlamofireWrapper: NSObject {
149150
150151 // MARK: - Multipart Form Data
151152
152- @objc public func POSTParametersHeadersConstructingBodyWithBlockProgressSuccessFailure(
153+ // Clean API: New shorter method name for multipart upload
154+ @objc public func uploadMultipart(
153155 _ urlString: String ,
154- _ parameters: NSDictionary ? ,
155156 _ headers: NSDictionary ? ,
156157 _ constructingBodyWithBlock: @escaping ( MultipartFormDataWrapper ) -> Void ,
157158 _ progress: ( ( Progress ) -> Void ) ? ,
@@ -233,7 +234,8 @@ public class AlamofireWrapper: NSObject {
233234
234235 // MARK: - Upload Tasks
235236
236- @objc public func uploadTaskWithRequestFromFileProgressCompletionHandler(
237+ // Clean API: Upload file
238+ @objc public func uploadFile(
237239 _ request: URLRequest ,
238240 _ fileURL: URL ,
239241 _ progress: ( ( Progress ) -> Void ) ? ,
@@ -280,7 +282,8 @@ public class AlamofireWrapper: NSObject {
280282 return afRequest. task
281283 }
282284
283- @objc public func uploadTaskWithRequestFromDataProgressCompletionHandler(
285+ // Clean API: Upload data
286+ @objc public func uploadData(
284287 _ request: URLRequest ,
285288 _ bodyData: Data ,
286289 _ progress: ( ( Progress ) -> Void ) ? ,
@@ -327,6 +330,82 @@ public class AlamofireWrapper: NSObject {
327330 return afRequest. task
328331 }
329332
333+ // MARK: - Download Tasks
334+
335+ // Clean API: Download file with streaming to disk (optimized, no memory loading)
336+ @objc public func downloadToFile(
337+ _ urlString: String ,
338+ _ destinationPath: String ,
339+ _ headers: NSDictionary ? ,
340+ _ progress: ( ( Progress ) -> Void ) ? ,
341+ _ completionHandler: @escaping ( URLResponse ? , String ? , Error ? ) -> Void
342+ ) -> URLSessionDownloadTask ? {
343+
344+ guard let url = URL ( string: urlString) else {
345+ let error = NSError ( domain: " AlamofireWrapper " , code: - 1 , userInfo: [ NSLocalizedDescriptionKey: " Invalid URL " ] )
346+ completionHandler ( nil , nil , error)
347+ return nil
348+ }
349+
350+ var request : URLRequest
351+ do {
352+ request = try requestSerializer. createRequest (
353+ url: url,
354+ method: . get,
355+ parameters: nil ,
356+ headers: headers
357+ )
358+ } catch {
359+ completionHandler ( nil , nil , error)
360+ return nil
361+ }
362+
363+ // Create destination closure that moves file to the specified path
364+ let destination : DownloadRequest . Destination = { temporaryURL, response in
365+ let destinationURL = URL ( fileURLWithPath: destinationPath)
366+
367+ // Ensure parent directory exists
368+ let parentDirectory = destinationURL. deletingLastPathComponent ( )
369+ try ? FileManager . default. createDirectory ( at: parentDirectory, withIntermediateDirectories: true , attributes: nil )
370+
371+ return ( destinationURL, [ . removePreviousFile, . createIntermediateDirectories] )
372+ }
373+
374+ var downloadRequest = session. download ( request, to: destination)
375+
376+ // Apply server trust evaluation if security policy is set
377+ if let secPolicy = securityPolicy, let host = url. host {
378+ downloadRequest = downloadRequest. validate { _, response, _ in
379+ do {
380+ try secPolicy. evaluate ( response. serverTrust!, forHost: host)
381+ return . success( Void ( ) )
382+ } catch {
383+ return . failure( error)
384+ }
385+ }
386+ }
387+
388+ // Download progress
389+ if let progress = progress {
390+ downloadRequest = downloadRequest. downloadProgress { progressInfo in
391+ progress ( progressInfo)
392+ }
393+ }
394+
395+ // Response handling
396+ downloadRequest. response ( queue: . main) { response in
397+ if let error = response. error {
398+ completionHandler ( response. response, nil , error)
399+ return
400+ }
401+
402+ // Return the destination path on success
403+ completionHandler ( response. response, destinationPath, nil )
404+ }
405+
406+ return downloadRequest. task as? URLSessionDownloadTask
407+ }
408+
330409 // MARK: - Helper Methods
331410
332411 private func createNSError( from error: Error , response: HTTPURLResponse ? , data: Data ? ) -> NSError {
0 commit comments