         
         if let image = self.item.image {
             self.image = image
-        } else if let URL = self.item.imageURL {
-            if URL.isFileURL {
-                try! self.image = UIImage(data: Data(contentsOf: URL as URL))
+        } else if let _ = self.item.imageURL {
+            self.downloadURL = self.item.imageURL
+            self.reuseIdentifier = self.downloadURL?.hash
+        } else {
+            assert(false)
+        }
+    }
+    
+    override func fetchContent(withProgressBlock progressBlock: @escaping ((_ progress: Float) -> Void), completeBlock: @escaping ((_ data: Any?, _ error: Error?) -> Void)) {
+        if let image = self.image {
+            completeBlock(image, nil)
+            return
+        }
+        
+        let reuseIdentifier = self.reuseIdentifier
+        
+        let checkProgressBlock = { [weak self] (progress: Float) in
+            guard reuseIdentifier == self?.reuseIdentifier else { return }
+         
+            DispatchQueue.main.async {
+                progressBlock(progress)
+            }
+        }
+        
+        let checkCompleteBlock = { [weak self] (data: Any?, error: Error?) in
+            guard reuseIdentifier == self?.reuseIdentifier else { return }
+            
+            DispatchQueue.main.async {
+                completeBlock(data, error)
+            }
+        }
+        
+        if let _ = self.downloadURL {
+            if let extraInfo = self.item.extraInfo, let originalURL = extraInfo[DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL] as? NSURL {
+                SDImageCache.shared().queryCacheOperation(forKey: originalURL.absoluteString, done: { (_, _, cacheType) in
+                    if cacheType != .none {
+                        self.downloadURL = originalURL
+                    }
+                    
+                    self.asyncFetchImage(with: self.downloadURL!, progressBlock: checkProgressBlock, completeBlock: checkCompleteBlock)
+                })
             } else {
-                self.downloadURL = self.item.imageURL
-                self.reuseIdentifier = self.downloadURL?.hash
-                
-                if let extraInfo = self.item.extraInfo, let originalURL = extraInfo[DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL] as? NSURL {
-                    if self.downloadURL == originalURL{
-                        self.downloadOriginalImageButton.isHidden = true
-                    } else if SDImageCache.shared().imageFromCache(forKey: originalURL.absoluteString) != nil {
+                self.asyncFetchImage(with: self.downloadURL!, progressBlock: checkProgressBlock, completeBlock: checkCompleteBlock)
+            }
+        } else if let asset = self.asset {
+            self.asyncFetchImage(with: asset, progressBlock: checkProgressBlock, completeBlock: checkCompleteBlock)
+        } else {
+            assert(false)
+        }
+    }
+    
+    override func updateContentView(with content: Any) {
+        super.updateContentView(with: content)
+        
+        if let extraInfo = self.item.extraInfo, let originalURL = extraInfo[DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL] as? NSURL {
+            if self.downloadURL == originalURL {
+                self.downloadOriginalImageButton.isHidden = true
+            } else {
+                SDImageCache.shared().queryCacheOperation(forKey: originalURL.absoluteString, done: { (_, _, cacheType) in
+                    if cacheType != .none {
                         self.downloadOriginalImageButton.isHidden = true
                     } else {
                         self.updateDownloadOriginalButtonTitle()
                         self.downloadOriginalImageButton.isEnabled = true
                         self.downloadOriginalImageButton.isHidden = false
                     }
-                } else {
-                    self.downloadOriginalImageButton.isHidden = true
-                }
-            }
-        } else {
-            assert(false)
+                })
+            }
+        } else {
+            self.downloadOriginalImageButton.isHidden = true
         }
     }
     

    @objc private func downloadOriginalImage() {
        if let extraInfo = self.item.extraInfo, let originalURL = extraInfo[DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalURL] as? NSURL {
            self.downloadOriginalImageButton.isEnabled = false
            
            self.downloadImage(with: originalURL, progressBlock: { [weak self] (progress) in
                self?.updateDownloadOriginalButton(with: progress)
            }, completeBlock: { (data, error) in
                if error == nil {
                    self.setNeedsUpdateContent()
                    self.downloadOriginalImageButton.isHidden = true
                } else {
                    self.downloadOriginalImageButton.isEnabled = true
                    self.updateDownloadOriginalButtonTitle()
                }
            })
        }
    }
    
    private func downloadImage(with URL: NSURL, progressBlock: @escaping ((_ progress: Float) -> Void),
                               completeBlock: @escaping ((_ data: Any?, _ error: Error?) -> Void)) {
        let key = URL.absoluteString
        let reuseIdentifier = self.reuseIdentifier!
        
        SDImageCache.shared().queryCacheOperation(forKey: key) { (image, data, cacheType) in
            if image != nil || data != nil {
                completeBlock(image ?? data, nil)
            } else {
                SDWebImageDownloader.shared().downloadImage(with: URL as URL,
                                                            options: SDWebImageDownloaderOptions.lowPriority,
                                                            progress: { [weak self] (receivedSize, expectedSize, targetURL) in
                                                                guard let strongSelf = self, reuseIdentifier == strongSelf.reuseIdentifier else { return }
                                                                
                                                                DispatchQueue.main.async {
                                                                    progressBlock(Float(receivedSize) / Float(expectedSize))
                                                                }
                    }, completed: { [weak self] (image, data, error, finished) in
                        var success = false
                        if (image != nil || data != nil) && finished {
                            SDImageCache.shared().store(image, imageData: data, forKey: key, toDisk: true, completion: nil)
                            success = true
                        } else {
                            success = false
                        }
                        
                        guard let strongSelf = self, reuseIdentifier == strongSelf.reuseIdentifier else { return }
                        
                        if success {
                            completeBlock(image ?? data, nil)
                        } else {
                            let error = NSError(domain: Bundle.main.bundleIdentifier!, code: -1, userInfo: [
                                NSLocalizedDescriptionKey : "获取图片失败"
                                ])
                            completeBlock(nil, error)
                        }
                })
            }
        }
    }
    
    private func updateDownloadOriginalButtonTitle() {
        if let extraInfo = self.item.extraInfo, let fileSize = extraInfo[DKPhotoGalleryItemExtraInfoKeyRemoteImageOriginalSize] as? NSNumber {
            self.downloadOriginalImageButton.setTitle("下载原图(\(self.formattedFileSize(fileSize.uintValue)))", for: .normal)
        } else {
            self.downloadOriginalImageButton.setTitle("下载原图", for: .normal)
        }
        self.updateDownloadOriginalButtonFrame()
    }
    
    private func updateDownloadOriginalButton(with progress: Float) {
        if progress > 0 {
            self.downloadOriginalImageButton.setTitle(String(format: "%.0f%%", progress * 100), for: .normal)
            self.updateDownloadOriginalButtonFrame()
        }
    }
    
    private func updateDownloadOriginalButtonFrame() {
        self.downloadOriginalImageButton.sizeToFit()
        
        let buttonWidth = max(100, self.downloadOriginalImageButton.bounds.width)
        let buttonHeight = CGFloat(25)
        
        self.downloadOriginalImageButton.frame = CGRect(x: (self.view.bounds.width - buttonWidth) / 2,
                                                        y: self.view.bounds.height - buttonHeight - 20,
                                                        width: buttonWidth,
                                                        height: buttonHeight)
    }
    
    private func formattedFileSize(_ fileSize: UInt) -> String {
        let tokens = ["B", "KB", "MB", "GB", "TB"]
        
        var convertedSize = Double(fileSize)
        var factor = 0
        
        while convertedSize > 1024 {
            convertedSize = convertedSize / 1024
            factor = factor + 1
        }
        
        if factor == 0 {
            return String(format: "%4.0f%@", convertedSize, tokens[factor])
        } else {
            return String(format: "%4.2f%@", convertedSize, tokens[factor])
        }
    }
    

        self.reuseIdentifier = nil
        self.downloadURL = nil
        self.image = nil
        self.asset = nil
        self.downloadOriginalImageButton.isHidden = true
    }
    
}
