stefan-niedermann / nextcloud-commons

Library for common Nextcloud operations, like a Glide-SSO integration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I can't get thumbnails from nextcloud server.

matiasdelellis opened this issue · comments

Hi @stefan-niedermann
I am trying to use this library to get the thumbnails from the nexcloud server, and use glide to apply them to an imageView. According to the description this is the correct library but I fail to use it.. 😞

Always fails with a 400 error

V/SingleSignOnLibraryGlideModule: Replacing default implementation for GlideUrl with SingleSignOnLibraryGlideModule.
D/com.nextcloud.android.sso.api.NetworkRequest: [connectApiWithBackoff] connectApiWithBackoff() called from Thread: [Thread-2]
D/com.nextcloud.android.sso.api.NetworkRequest: [connectApiWithBackoff] trying to connect..
D/com.nextcloud.android.sso.api.AidlNetworkRequest: [connect] Binding to AccountManagerService for type [nextcloud]
D/com.nextcloud.android.sso.api.NetworkRequest: [connect] connect() called [main] Account-Type: [nextcloud]
D/com.nextcloud.android.sso.api.AidlNetworkRequest: [connect] Component name is: [com.nextcloud.client]
V/SingleSignOnStreamFetcher: NextcloudRequest(method=GET, header={User-Agent=[Dalvik/2.1.0 (Linux; U; Android 10; moto g(8) plus Build/QPI30.28-Q3-28-26)]}, parameter={}, requestBody=null, url=/index.php/core/preview, token=null, packageName=null, accountName=null, bodyAsStream=null, followRedirects=false)
V/com.nextcloud.android.sso.api.AidlNetworkRequest: [waitForApi] - api not ready yet.. waiting [glide-source-thread-0]
D/com.nextcloud.android.sso.api.AidlNetworkRequest: [connect] Bound to AccountManagerService successfully
D/com.nextcloud.android.sso.api.AidlNetworkRequest: [onServiceConnected] called from Thread: [main] with IBinder [ComponentInfo{com.nextcloud.client/com.owncloud.android.services.AccountManagerService}]: android.os.BinderProxy@7abe8f3
V/SingleSignOnStreamFetcher: SSO API successfully initialized
D/com.nextcloud.android.sso.api.AidlNetworkRequest: copy data from service finished
W/ud.testglidess: Accessing hidden method Landroid/app/ActivityThread;->currentApplication()Landroid/app/Application; (greylist, reflection, allowed)
W/Glide: Load failed for https://delellis.com.ar/index.php/core/preview?fileId=187239&x=512&y=512&a=false&v=3168c3d339e99c870bd9d92a666526a4 with size [1080x336]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There was 1 cause:
    com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException(La petición HTTP ha fallado con un código de estado: 400)
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, REMOTE
    There was 1 cause:
    com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException(La petición HTTP ha fallado con un código de estado: 400)
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException: La petición HTTP ha fallado con un código de estado: 400
I/Glide: Root cause (1 of 1)
    com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException: La petición HTTP ha fallado con un código de estado: 400
        at com.nextcloud.android.sso.api.AidlNetworkRequest.performNetworkRequestV2(AidlNetworkRequest.java:172)
        at com.nextcloud.android.sso.api.NextcloudAPI.performNetworkRequestV2(NextcloudAPI.java:168)
        at it.niedermann.nextcloud.sso.glide.SingleSignOnStreamFetcher.loadData(SingleSignOnStreamFetcher.kt:64)
        at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:70)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:63)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
     Caused by: java.lang.IllegalStateException: []
    
        at com.nextcloud.android.sso.InputStreamBinder.processRequestV2(InputStreamBinder.java:429)
        at com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestAndBodyStreamV2(InputStreamBinder.java:125)
        at com.nextcloud.android.sso.InputStreamBinder.performNextcloudRequestV2(InputStreamBinder.java:108)
        at com.nextcloud.android.sso.aidl.IInputStreamService$Stub.onTransact(IInputStreamService.java:158)
        at android.os.Binder.execTransactInternal(Binder.java:1036)
        at android.os.Binder.execTransact(Binder.java:1003)

As the questions will be very long, prepare a test to exemplify. This is just an activity, with a button to select the account, and an imageView to apply the image.

The main code:

I guess it should be pretty simple to read, and know if I'm forgetting something but If you want to try, you should just change this URL to any thumbail url acquired from the browser

https://github.com/matiasdelellis/TestGlideSSO/blob/master/app/src/main/java/com/nextcloud/testglidesso/MainActivity.java#L88

Thank you very much for all your work!. 😄

Wow, the lib is like 2 days old and there is a consumer? 😆

Until now i only used it to fetch user avatars, but in theory it also should work for file previews. You are getting HTTP Status Code 400 as a response, maybe we have to add a Header like OCS-APIRequest: true or so.

Short update: Adding the header isn't necessary, because

The 'OCS-APIREQUEST' header will be automatically added by the Nextcloud SSO Library. Please remove the header before making a request

I opened an issue at the upstream SSO library, because this behavior is also reproducible completely without Glide or this library:

nextcloud/Android-SingleSignOn#266

Wow, the lib is like 2 days old and there is a consumer? laughing

I had been testing it for a while, but now with a mayor version, I thought it would be a good time to try again and bother.. 🙈 😅

I opened an issue at the upstream SSO library, because this behavior is also reproducible completely without Glide or this library:

Great.. Thanks again.

@matiasdelellis can you please try my branch solution:

implementation 'com.github.stefan-niedermann.nextcloud-commons:sso-glide:17-keep-query-params-SNAPSHOT'

Geat... Now worked perfectly.. I can see my thumbails..

It only fails in a few with 404 code. But they are some images with space..

eg: https://delellis.com.ar/core/preview.png?file=/Documents/Nextcloud%20flyer.pdf&x=512&y=512

..probably due to double encode, but as for my report, I think it works fine.. 😄

Thanks you!.

Okay, i just tagged 1.2.1 which contains this fix.

About the double encoding: i don't do any encoding on my side, so this should be handled in the 3rd-party app (or open an issue upstream :) )

@matiasdelellis you should update to 1.2.2, otherwise images will not be loaded when the nextcloud is installed in a subdirectory, like example.com/nextcloud instead of nextcloud.example.com.

Ok.. Thanks a lot, 😄