Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide - adding header to request

Is there a method to add a custom header to request when an image is downloaded? I can use volley or okhttp in Glide.

I tried adding a cookie to the cookiemanager in okhttpclient, but it didn't help.

Is there a method to debug request response in Glide?

like image 313
tomi Avatar asked Jan 23 '15 09:01

tomi


People also ask

How do you post images from URL on Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

What is placeholder Glide?

Placeholders are Drawables that are shown while a request is in progress.


2 Answers

Since 3.6.0 it's possible to set custom headers for each request:

GlideUrl glideUrl = new GlideUrl("url", new LazyHeaders.Builder()     .addHeader("key1", "value")     .addHeader("key2", new LazyHeaderFactory() {         @Override         public String buildHeader() {             String expensiveAuthHeader = computeExpensiveAuthHeader();             return expensiveAuthHeader;         }     })     .build());  Glide....load(glideUrl)....; 
like image 152
TWiStErRob Avatar answered Sep 17 '22 19:09

TWiStErRob


Try this:

ImageView imgThumb = itemView.findViewById(R.id.image_thumb);  GlideUrl url = new GlideUrl("https://your-url.com", new LazyHeaders.Builder()                 .addHeader("User-Agent", "your-user-agent")                 .build());  RequestOptions options = new RequestOptions()     .diskCacheStrategy(DiskCacheStrategy.NONE);  Glide.with(mContext).load(glideUrl)                     .transition(withCrossFade())                     .thumbnail(0.5f)                     .apply(options)                     .into(imgThumb); 

The Glide reference is:

implementation 'com.github.bumptech.glide:glide:4.6.1' 
like image 20
educoutinho Avatar answered Sep 21 '22 19:09

educoutinho