1

I'm working on an app that displays images stored in my personal Google Drive account in a public folder, and I access them and load into ImageView with the next url:

https://drive.google.com/uc?export=download&id=imageId

And so I use the next piece of code to load an image into an ImageView using Picasso:

String imageLink="https://drive.google.com/uc?export=download&id="+imageId;
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Picasso.with(this).load(imageLink).into(imageView);

And it was working fine until yesterday, from when it started to work randomly, let's say, sometimes image is loaded and sometimes not and you simply see a blank ImageView (don't know the reason).

It's really weird, because when it stops working then it stops working for a while, and then, after many attempts it can suddenly start working again and so :s

I've also tried the next url with same results:

https://drive.google.com/uc?id=imageId

I guess it could be a better to implement Google Drive Rest API into my app, but I was reading the documentation and I don't find it trivial, so decided to give up.

I prefer to use just the url method because it's much simpler, but in case you think API is the only solution a working example would be much appreciated.

BTW; if I use the url in a browser the image is displayed/downloaded correctly, athought it is converted to something like this:

https://doc-0g-bs-docs.googleusercontent.com/docs/securesc/76n246a8a2lbkhsdab1lp67gphlf8cpm/i1ue4k811iltbcb797njulf061flfdpg/2581292320200/05260912172022660129/05860924272025660129/10_DnmLE22AvRB2eRHaTi8RLCrgVopoHC?authuser=0&nonce=2td2b6i2brn2u&user=02222914122025660129&hash=2odo2ssceotbocirunbn4vqj26l2h6fl

Any help?

Edit: I noted that Google Drive response is a plain http 403 error with no additional description (or at least Picasso Exception won't show additional data).

Edit1: I suspect it may have something to do with Internet connection. When it stops working (returning the 403) if I reboot my phone it starts working again (only with data connection, not with wifi). Maybe Google Drive is blocking my mobile connection ip after many requests (or at least is the only thing that come to my mind).

Edit2: Maybe it's only me that I'm doing many tests/requests from the same ip and that's why Google Drive blocks my ip or maybe it's a general issue and if plenty of users do requests at the same time the same will happen? I need to find a solution, and if there is no one (wouldn't believe that) at least advices on other free image hosting services I can use to load images in my app (into an ImageView) from the cloud.

Diego Perez
  • 2,188
  • 2
  • 30
  • 58
  • What's the reason for using a public image on Google Drive (vs somewhere else) as you can see its not designed for what you are doing :-) – Blundell Feb 15 '20 at 18:53
  • Hello @Blundell, didn't really thought couldn't use Google Drive for that, in the end you have a public folder and it is supposed you can use your file(s) public url as you need. As I salid, I can see the image perfectly in the browser, it is only giving random problems on Android. Said that, doesn't come to my mind any other free images hosting service right now, and I also wouldn't like to be in the need of changing the images url, as they're stored in a sqlite database and app is already on market, so I wouldn't like to be in the need to update database. – Diego Perez Feb 15 '20 at 19:06
  • when I went to the url you shared it says "Internal server error". (the raw url you shared). For the other link: https://drive.google.com/uc?id=imageId it's not a direct link to an image, it redirects to the correct URL, thats not a good idea for image loading. I personally wouldn't use Google Drive. An S3 bucket would be my goto (or Microsoft/Google equiv). – Blundell Feb 15 '20 at 19:09
  • This is an example of an url (with correct imageId) that works on browser: https://drive.google.com/uc?id=10_DnmLE66AvRB6eRHaTi8RLCrgVopoHC. It's doing a redirection but even using the redirection url it's not working, and BTW, I'm not using Amazon's S· as it's not free, I need a free service, and as I said it was working with no problem until yesterday @Blundell. Couldn't even think I could have this kind of problem some day when started the project. – Diego Perez Feb 15 '20 at 19:15
  • S3 does have a free tier https://aws.amazon.com/s3/pricing/ . I'd just be worried about Google Drive "just stopped yesterday" because its not designed as an image server, yesterday they probably refreshed their cache or something not under your control. – Blundell Feb 15 '20 at 19:16
  • Here (last post) it says it is possible: https://stackoverflow.com/questions/25148291/how-to-integrate-google-drive-with-picasso-on-android but anyway, I've tried Google Photos and I'm also having problems with image not loading. Something beyond my understanding right now @Blundell. – Diego Perez Feb 15 '20 at 19:31
  • You need a hosting service, not an image viewing service. – Blundell Feb 15 '20 at 21:05
  • Google Drive can work as a hosting service, but this is not the problem. I don't see any reason why images keep on loading randomly. From moments they start working with the url I've provided in post, and from time to time they stop loading with no aparent reason. If Google Drive were the problem they wouldn't load not even once. – Diego Perez Feb 19 '20 at 15:08
  • As I'm using Picasso and it has an image load callback I was now able to see a http 403 error (when images doesn't load), so it's apparently a forbidden error, but it has nonsense as it's a public folder and images has a public link and... they work randomly! – Diego Perez Feb 19 '20 at 15:20
  • Dude, how can I explain. You need a hosting service, not a user facing image viewing service. Google Drive has not SLA to guarantee how it works if you call it from an automated service. Only when called from its own website. – Blundell Feb 19 '20 at 23:03
  • Can we use WebView instead of ImageView. I mean using webview as imageview. – parag pawar May 15 '20 at 15:52
  • 1
    Of course you can @parag pawar. You will have to write html code to display the image. If you load images from the web directly, then no problem, you just use but if you have to download the images first, then you should store them in assets and then you can access them in webview like so: htmlText += " src: url(\"file:///android_asset/" + customFont + "\")"; (this is just an example where I compose a string with the webview html) – Diego Perez May 15 '20 at 17:18
  • Oh thank you. This solves my major problem. By using will do i guess. I won't need to download the image. – parag pawar May 15 '20 at 17:26
  • 1
    I'm glad @parag pawar. Let me know if you need further help. – Diego Perez May 15 '20 at 18:01
  • Just wanted to make sure. This will work with service account. I'm uploading with Drive Api with service account and storing fileId in firebase. I'm fetching file id and using above method to display image on webview. – parag pawar May 16 '20 at 07:37
  • Never worked with Google Drive Api, but it should work as long as the url you put into – Diego Perez May 17 '20 at 10:23
  • @Diego Perez, can you find any solution for errorcode 403 ? – Noor Hossain Oct 16 '20 at 11:17

0 Answers0