Downloads from Website to Mobile
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Downloads from Website to Mobile
I am wondering if there is a way to allow a mobile device to download a .txt file from a website like a desktop web browser does.
1) The website automatically transfers a .txt file to a desktop web browser upon executing javascript.
2) The mobile device, to my knowledge, does not download the .txt file when executing javascript using mobileControlDo "execute."
3) The mobile browser is a browser widget created by mobileControlCreate.
Is there any way for the mobile's web browser widget to download this .txt file?
1) The website automatically transfers a .txt file to a desktop web browser upon executing javascript.
2) The mobile device, to my knowledge, does not download the .txt file when executing javascript using mobileControlDo "execute."
3) The mobile browser is a browser widget created by mobileControlCreate.
Is there any way for the mobile's web browser widget to download this .txt file?
Re: Downloads from Website to Mobile
Hi JereMiami,
some questions:
Does the TXT file have a fixed URL?
If yes, you could simply download it "manually (with a script)" with "load url..." or "put url..."
We have write permission in the users Documents folder, so you should load it to
-> specialfolderpath("documents") & "/name_of_your_file.txt"
Otherwise this would be a VERY HIGH security hole!
So what are you actually using here?
Best
Klaus
some questions:
Does the TXT file have a fixed URL?
If yes, you could simply download it "manually (with a script)" with "load url..." or "put url..."
We have write permission in the users Documents folder, so you should load it to
-> specialfolderpath("documents") & "/name_of_your_file.txt"
No, and I guess on the desktop there will be an alert before downloading the file, right?2) The mobile device, to my knowledge, does not download the .txt file when executing javascript using mobileControlDo "execute."
Otherwise this would be a VERY HIGH security hole!
There is a big difference between "the browser widget" and a native browser instance created with "mobilecreate...", like "mobilecontroldo..." does not work in a WIDGET!3) The mobile browser is a browser widget created by mobileControlCreate.
So what are you actually using here?
Best
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Downloads from Website to Mobile
My mobile apps download text files without any problem. There is no warning and the download is very fast. I've never done it from within a browser though, it's done as Klaus suggests by scripting the download in LC, saving the file to the documents folder, and then setting the html of the native browser control to the content of the file.
Getting the file from the server is easy, just use the "put url" syntax:
Getting the file from the server is easy, just use the "put url" syntax:
Code: Select all
put url <url to server file> into url <path to documents folder>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Downloads from Website to Mobile
Thanks, I will give it a try and let you know!
Re: Downloads from Website to Mobile
So I never was able to get this to work, unfortunately.
Here's what happens and what I am trying to do. No widgets involved. I use mobileControlCreate "browser" to open the native android browser.
First, I have the user navigate to a webpage. On that webpage is a form that is automatically completed and submitted using mobileControlDo "execute" (...). So far, so good.
On the desktop browser, a .txt file is automatically (without asking permission) downloaded. The .txt file gives a unique address specifying where the user will be redirected to next.
On android, however, it either: (1) does nothing after submitting the form (I have confirmed that the form is indeed submitted via mobileControlDo "execute"), or (2) it downloads the .txt file to somewhere that I am not familiar with. I simply cannot tell if it is downloading the .txt file and putting it somewhere that I have not been able to locate (it's not in the engine, resources, documents, cache etc.) or if it is simply not downloading the .txt file at all.
I would love, although not entirely necessary (but it would be super nice) to read that .txt file so I can automatically redirect the user to the new webpage. I am just unable to find it or download it through the native android browser (i.e., mobieControlCreate, not the widget). Any thoughts on how that can be done or where that pesky .txt file is?
Here's what happens and what I am trying to do. No widgets involved. I use mobileControlCreate "browser" to open the native android browser.
First, I have the user navigate to a webpage. On that webpage is a form that is automatically completed and submitted using mobileControlDo "execute" (...). So far, so good.
On the desktop browser, a .txt file is automatically (without asking permission) downloaded. The .txt file gives a unique address specifying where the user will be redirected to next.
On android, however, it either: (1) does nothing after submitting the form (I have confirmed that the form is indeed submitted via mobileControlDo "execute"), or (2) it downloads the .txt file to somewhere that I am not familiar with. I simply cannot tell if it is downloading the .txt file and putting it somewhere that I have not been able to locate (it's not in the engine, resources, documents, cache etc.) or if it is simply not downloading the .txt file at all.
I would love, although not entirely necessary (but it would be super nice) to read that .txt file so I can automatically redirect the user to the new webpage. I am just unable to find it or download it through the native android browser (i.e., mobieControlCreate, not the widget). Any thoughts on how that can be done or where that pesky .txt file is?
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Downloads from Website to Mobile
The file will be in the app's sandbox. File managers can't access the sandbox, but your app can. Where does your download handler put it? You can only write to specialfolderpath("documents") so that's where it needs to go.
To see the file, write a handler that retrieves it from the documents folder and displays it in an answer dialog or a special debugging field if it's very long.
Can you post the lines of script that do the download?
To see the file, write a handler that retrieves it from the documents folder and displays it in an answer dialog or a special debugging field if it's very long.
Can you post the lines of script that do the download?
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Downloads from Website to Mobile
This is Dropbox and I am revisiting this issue because of a recent change in their API choices (i.e., legacy vs. scoped). You can only use scoped now and by default the access token has a limited shelf life. So, I would really like to generate an access token for the user because the access token can be a bit challenging to achieve now.
Here's the portion of the script that has the .txt file issue:
Now, at this point, the desktop browser (Chrome) will automatically download the .txt file. The .txt file contains a portion of the url that it would redirect the user to for the user to generate the API access token (it would redirect the user if they clicked the button, but since we are submitting the form through javascript, we stay on the same page.) The .txt file comes from a different download link "https://www.dropbox.com/developers/apps/create/submit" (which is neither the same url as above nor the url the user would be redirected to). The site never directs you there, but rather just downloads the .txt file from that url (according to the desktop browser).
You can be sure because the following code does not work, which is attempting to "catch" the .txt file after submitting the form:
So, I guess, what I am really asking is: "How do I catch that .txt file like it does on a desktop browser so I can access it?"
Here's the portion of the script that has the .txt file issue:
Code: Select all
on browserFinishedLoading pUrl
global gAccessToken
put empty into gAccessToken
if pUrl = "https://www.dropbox.com/developers/apps/create" then
completeForm
end if
end browserFinishedLoading
on completeForm
set the defaultFolder to specialFolderPath("documents")
mobileControlDo sBrowserId, "execute", "document.getElementById('scoped').checked = true";
mobileControlDo sBrowserId, "execute", "document.getElementById('scoped').click()";
mobileControlDo sBrowserId, "execute", "document.getElementById('app_folder_permission').checked = true";
mobileControlDo sBrowserId, "execute", "document.getElementById('app_folder_permission').click()"
mobileControlDo sBrowserId, "execute", "document.forms['create-app-form']['name'].value += 'uniquenameforanapp'";
wait 2 seconds
mobileControlDo sBrowserId, "execute", "document.forms['create-app-form'].submit()";
wait 2 seconds
mobileControlDo sBrowserId, "execute", "document.forms['user-form'].submit()";
end completeForm
You can be sure because the following code does not work, which is attempting to "catch" the .txt file after submitting the form:
Code: Select all
on browserFinishedLoading pUrl
if pUrl = "https://www.dropbox.com/developers/apps/create/submit" then
put specialFolderPath("documents") & "/submit.txt" into tFileName
put pUrl into url ("binfile:" & tFileName)
if tFileName contains ".txt" then
put it into URL ("file:"& tFileName)
else
put it into URL ("binfile:"& tFileName)
end if
put the result into tResult
if tResult is empty then
answer "Done"&cr&"File copied into Documents"
else
answer error tResult
end if
end if
end browserFinishedLoading
So, I guess, what I am really asking is: "How do I catch that .txt file like it does on a desktop browser so I can access it?"
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Downloads from Website to Mobile
I'm a little confused. This line:
puts a url string into a file in the documents folder. You don't really need to use binfile for that, but since you are, I wonder if you're trying to get the file content of that URL? If so, you'd want
but your explanation indicates you do want the URL in the file.
What's in "it" when this line executes:
Remote debugging would be handy here, but you can also just put some temporary answer dialogs in the script if you want to see the values of the variables.
TFileName will always contain ".txt" in this case, so no need for an "if" clause.
Code: Select all
put pUrl into url ("binfile:" & tFileName)
Code: Select all
put url pUrl into url ("binfile:" & tFileName)
What's in "it" when this line executes:
Code: Select all
put it into URL ("file:"& tFileName)
Code: Select all
put specialFolderPath("documents") & "/submit.txt" into tFileName
put pUrl into url ("binfile:" & tFileName)
if tFileName contains ".txt" then
put it into URL ("file:"& tFileName)
else
put it into URL ("binfile:"& tFileName)
end if
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Downloads from Website to Mobile
Thank you! I will have a go at this tomorrow morning and let you know how it goes.
Re: Downloads from Website to Mobile
You are correct. I just want the .txt file in the "documents" folder to read from. But unfortunately we don't get to that point. Here's where I believe it ends.I'm a little confused. This line:
CODE: SELECT ALL
put pUrl into url ("binfile:" & tFileName)
puts a url string into a file in the documents folder. You don't really need to use binfile for that, but since you are, I wonder if you're trying to get the file content of that URL? If so, you'd want
CODE: SELECT ALL
put url pUrl into url ("binfile:" & tFileName)
but your explanation indicates you do want the URL in the file.
Code: Select all
mobileControlDo sBrowserId, "execute", "document.forms['create-app-form'].submit()";
answer the result
Now, had we submitted the form on the desktop, we would have received what we see in the image attached to this post (a .txt file called "submit").
When you look at the properties of this file, it tells you the download link is "https://www.dropbox.com/developers/apps/create/submit." So I thought to plug in the following code in the browserFinishedLoading command:
Code: Select all
on browserFinishedLoading pUrl
global gAccessToken
put empty into gAccessToken
if pUrl = "https://www.dropbox.com/developers/apps/create/submit" then
answer "File on its way!"
put specialFolderPath("Documents") & "/submit.txt" into tFileName
...
end browserFinishedLoading
-
- VIP Livecode Opensource Backer
- Posts: 7215
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Downloads from Website to Mobile
It sounds like pURL doesn't contain what you'd expect, so I'd add an answer dialog at the beginning of the handler to be sure it's returning the right URL:I do not get a "File on its way!" dialog box after the answer command.
Code: Select all
on browserFinishedLoading pUrl
global gAccessToken
ANSWER PURL -- does this match what you expect?
put empty into gAccessToken
if pUrl = "https://www.dropbox.com/developers/apps/create/submit" then
answer "File on its way!"
put specialFolderPath("Documents") & "/submit.txt" into tFileName
...
end browserFinishedLoading
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com