Download image using AlamofireImage?

Is there a way to upload an image using AlamofireImage and get some information about the download progress while using the power of UIImage Extensions, Image Filters and Image Cache ?

I know that I can refuse simple Alamofire.request+ responseImage, but I would like to simplify the task and use the UIImageView extension .

Thanks!

+4
source share
3 answers

At the moment, there is no way to use AlamofireImage together with the extension UIImageViewto receive progress updates when loading an image. The reason it was not added initially was because most users did not seem to need such a feature. I would like to discuss more to find out if there is this feature that we would like to add to AlamofireImage in a future version.

Could you open the problem going through your use case? I just wanted to know exactly how you expect this to work, and why you really need progress reports.

+1
source

Try this with Swift 3.0.2:

let utilityQueue = DispatchQueue.global(qos: .utility)
let url = "http://kingofwallpapers.com/code/code-006.jpg"

    Alamofire.download(url)
        .downloadProgress(queue: utilityQueue) { progress in
            print("Download Progress: \(progress.fractionCompleted)")
        }
        .responseData { response in
            print("Response is \(response)")
            if let data = response.result.value {
                let image = UIImage(data: data)
            }
    }
+1
source

Alamofire

Alamofire.download(.GET, "url...", destination: destination)
         .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
             print(totalBytesRead)

             // This closure is NOT called on the main queue for performance
             // reasons. To update your ui, dispatch to the main queue.
             dispatch_async(dispatch_get_main_queue()) {
                 print("Total bytes read on main queue: \(totalBytesRead)")
             }
         }
         .response { _, _, _, error in
             if let error = error {
                 print("Failed with error: \(error)")
             } else {
                 print("Downloaded file successfully")
             }
         } 
0

Source: https://habr.com/ru/post/1614135/


All Articles