ARTICLE AD BOX
I’m using Kingfisher library in a SwiftUI chat view to display images using KFImage(url). I now need to retrieve the original downloaded image so I can upload it to my backend. However, when I extract the image Kingfisher gives me, the file size becomes larger than the original file. Because of the backend size limit, I must send the exact original file.
Here is what I've tried
KFImage(url) .cacheOriginalImage(true) .contextMenu { Button("Copy Image") { let cacheKey = url.cacheKey // Get original data synchronously from disk cache do { if let originalData = try ImageCache.default.diskStorage.value(forKey: cacheKey) { print("Original data size: \(originalData.count) bytes (~\(originalData.count / 1024 / 1024) MB)") } else { print("No cached data found") } } catch { print("Error retrieving cached data: \(error)") } } }And also I tried retrieveImage function to get the image and convert it to data. Its also giving much larger image than the original image.
KFImage(url) .cacheOriginalImage(true) .contextMenu { Button("Copy Image") { KingfisherManager.shared.retrieveImage(with: url, options: [.originalCache(.default)]) { result in switch result { case .success(let value): Task { @MainActor in if let dataA = value.image.jpegData(compressionQuality: 1.0) { print("Original data size: \(originalData.count) bytes (~\(originalData.count / 1024 / 1024) MB)") } } case .failure(let error): print("Error loading image: \(error)") } } } }Is there any other way to retrieve the exact original image without re-downloading it?
3371 gold badge6 silver badges21 bronze badges
1
Explore related questions
See similar questions with these tags.
