Debug download.html example. #55
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes
download.html[nearly] functional. The previous version did not work.I've made a few fixes and changes, including adding several convenience features.
downloadfilefunctionfileidwas ignored; value had been hard-coded, which wouldn't work.console.logs referenced "uploads"; now says download.localStorageso that you don't have to get a token each time.access_tokenwas assigned but unused; it's now trivially used.locationidwas assigned but unused. It's saved tolocalStoragenow, but is essentially unused.createClient, eg.listFilesis now recursive through folders.lifeFilesreads amaxdepthfrom the ui to limit the folder depth used.2to includeDemo Audio 2.mp3if using aclient_idwith all folder access.client_id.I realize this is slightly more complicated than a simplest case, but is the minimum I think you could give to demonstrate something approaching real-world usage. At just under 150 lines with html, it's not horrible. It is both folder & file listing plus download.
client_ids and private vs. all folder accessI noticed that there were two
client_idvalues being used throughout theexamplefolder:client_idof"3dunsTvYJsu", ALL FOLDERS accessclient_idof"p1WznE2dEPm", private access onlyI included both in the code here, though the pCloundSampleApp
client_idis hooked up by default. That does mean a user needs to put files in its app folder, which is why I added the message in case the app-specific folder is empty, as mentioned above.Strange server behavior
There are a few other things I'd clean up in a perfect world. I'd remove parent-scoped variables and change variable names to camelCase, for instance. But this seems to work fairly well, except...
The download doesn't seem to work! There's a CORS error, which means pCloud would need to change settings on the API side for this to work from a browser using the example code, even fixed.
It'll work from node, of course, or something else that isn't worried about CORS, but not from a browser on a non-pCloud domain.
I'll open an issue for that and reference it here. EDIT: Looks like it's been open a while, and the answer is that
getfilelinkisn't supposed to work with CORS. :sigh:If true, we should probably remove
download.html, right?I've also noticed I have to sign-in twice in the OAuth interface to get a token with the examples. That's strange, though it doesn't prevent the app from eventually functioning.
Thank you!