Greetings, I am not sure if it is the right if it ...
# android
s
Greetings, I am not sure if it is the right if it is the right channel, but I do hope some guidance and/or help. I have recently starting Using Glide to load Images from a REST API for a new project I am working and I have become somewhat desperate with an issue I am facing at the moment. I am trying to load images from an existing API, the issue is that the images come as encrypted Bytearray and cannot be read if not decrypted prior to being loaded to the imageView. The flow is as follows: LoadImage(id) -> OutputByteArray -> DecryptAES() -> assign decrypted bytearray/bitmap to imageView. I tried to look for tutorials and examples in Kotlin to do this step, but could not find any relevant sources(I am aware of ModelLoaders and DataRetrievers), but I could not understand how I could add that simple step of Decryption step through Glide
Copy code
// RecyclerViewListItem.kt

val encryptedImageEndpoint = "API_URL"
  val glideUrl = GlideUrl(encryptedImageEndpoint) { mapOf(Pair("Authorization", "Bearer $testToken")) }
  
  Glide.with(this.containerView).load(glideUrl).signature(ObjectKey(imageID))
                    .transition(DrawableTransitionOptions.withCrossFade()).thumbnail(0.25f)
               .apply(RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC).skipMemoryCache(true).override(selfReference.snapshotImage.width, selfReference.snapshotImage.height)
                            .placeholder(R.drawable.empty_result)
                    ).into(this.itemView.snapshotImage)

//before loading to imageVIiew I need the following to be done with the API Call response: val decryptedByteArray = CryptoCbc.decryptAesCBC(byteArrayFromResponse, sharedSecret)
p
Glide will happily use OkHttp to make its network requests - we’ve used that many times when we had to provide authentication headers when loading images - see https://bumptech.github.io/glide/int/okhttp3.html Given that OkHttp lets you intercept and rewrite both requests and responses - https://square.github.io/okhttp/interceptors/ I believe you could move the decryption step into an OkHttp interceptor and manipulate the byte array before Glide ever sees it or tries to push it into a view.
s
Thanks, i will check it out.