-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make resource more customizable #722
Comments
Maybe you could use the modifier for this. Please check the "Modify a request before sending" part in our cheat sheet in wiki. |
Yes, I could try and figure out the appropriate body for the request, the only problem is that it contains a lot of info which would have to be fetched from different APIs in Firebase, which is tedious compared to using their methods to handle it for you. Resource and ImageDownloader could be more customizable |
I am not sure what you want to do. Can you give some examples? |
in ImageDownloader there is a open method for customizing image downloads. The problem is that it relies on me knowing the URL. open func downloadImage(with url: URL, retrieveImageTask: RetrieveImageTask? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: ImageDownloaderProgressBlock? = nil, completionHandler: ImageDownloaderCompletionHandler? = nil) -> RetrieveImageDownloadTask? But in my case I have a closed function from an external library to figure out the URL. I only provide internal paths to their public API and eventually get a Data object. I want to be able to provide KingFisherManager a custom ImageDownloader which uses this external library (Firebase SDK) for downloading my images as Data, with all the other benefits of KingFisher, such as the UIImageView extensions, Cache and ImageProcessing |
What I am forced to use: // Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")
// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.getData(maxSize: 1 * 1024 * 1024) { data, error in
if let error = error {
// Uh-oh, an error occurred!
} else {
// Data for "images/island.jpg" is returned
let image = UIImage(data: data!)
}
} I would like to be able to provide a custom ImageDownloader for Kingfisher that uses this method, that way I don't need to know all the parameters Firebase eventually add to my URL, Kingfisher shouldn't have to know either, all Kingfisher should be worried about is the image itself, right? |
Hmm, currently the image downloader is a wrapper of a plain session and getting an image from url. It cannot be used for your case yet. I'd take a look at whether we could adopt to a more generic way while keeping the back compatibility. |
@valdirunars : Did you do a workaround for Kingfisher with Firebase? Would be really helpful. Thanks! |
Implemented as a part of version 5. Now you could use More information will be added to wiki later when it is released. |
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
Issue Description
What
Currently the library relies on developers providing a URL for each Resource but in many cases this is not fully available.
Other third party libraries often have a special way of creating network requests for a resource handling token & body for you.
In those cases, providing a simple URL is not enough to get all of the external library's functionalities.
Here it would be ideal to either allow developers to extend Resource in a more customizable manner.
Example
ImageDownloader
could be an abstract classImageDownloader<T: Resource>
. There could be aImageDownloader<URL>
which handles the default method ofsetImage(for url: URL ...)
This way all developers would have to do is provide a custom resource and implement an ImageDownloader for it.
Motivation
I'm developing an application using Google's popular BaaS, Firebase. The service has a custom way for me to download files (images in my case), which manages all authentication objects sent, making URL not enough and creating URLRequest with the correct data for this library tedious.
Other Comment
[Add anything else here]
The text was updated successfully, but these errors were encountered: