Page 1 of 2

Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 5:06 pm
by LeProfBard
Hi,
Long time LC user, needing to move reliable stacks & projects to web apps (thanks, C-19!). Here are some of my travails, can someone point me in the right direction, please?

I want to send the content of a variable (the output) from one stack (html5 standalone) to text file. For context, I'm using LC Hosting service, with full permissions assigned, and I have confirmed that the filepath is correct. I have tried a number of 'put', 'post', 'get' and 'write' commands, with no luck, with and without "open file URL for write", and/or "Load....", etc.

So, can someone help with the frustration? Why do these not work? Like everything else these days, deadlines matter...

1. Via 'put' : Put "NewContent" into line 1 of URL ["http://...txt"]

2. the POST hole: Post "NewContent" to line 2 of URL ["http://....txt"]

3. the open/write/close sequence:
open file URL ["http://....txt"] for text write
write "NewContent" to file URL ["http://....txt"] at EOF
close file URL ["http://....txt"]

4. The finish line: Of course, once I get the data in the text file, I want to retrieve it (via another stack), but nothing other than "Answer" has allowed me to access anything in the text file.

Thanx in advance!
L P B

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 5:27 pm
by Klaus
Hi L P B,

not sure, but try with just the relative (to your HTML5 runtime) pathname and FILE:

Code: Select all

...
put "NewContent" into line 1 of URL("file:your_data_file_here.txt")

## the result = EMPTY on success!
## so maybe this gives a hint what happened
if the result <> EMPTY then
   answer "Error:" && the result
end if
...

Best

Klaus

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 5:37 pm
by FourthWorld
Browsers do not allow unfettered access to the user's file system. Think about what could happen if they did.

Does this app really need to be confined to a browser window?

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 5:51 pm
by Klaus
Hm, I thought he wanted to let the HTML5 runtime write a file on the SERVER!?
Not? :D

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 6:03 pm
by LeProfBard
Yes, it's on the server, not on the client/user's file system.
Thanks,
L P B

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 6:44 pm
by FourthWorld
What is on the server to receive the data?

Re: Transfer to/ from html5 standalone and text file

Posted: Sun Apr 19, 2020 6:47 pm
by Klaus
LeProfBard wrote:
Sun Apr 19, 2020 6:03 pm
Yes, it's on the server, not on the client/user's file system.
Thanks,
L P B
OK, then try my script above.
"write permission" in that folder presumed! 8)

Re: Transfer to/ from html5 standalone and text file

Posted: Mon Apr 20, 2020 3:16 am
by LeProfBard
Hi Klaus (and FourthWorld--I've read and appreciated comments from both of you in many of the forums over the years, too)

No progress: the script apparently ran, but nothing was delivered to the text file, and there was no error code returned.

FourthWorld: you asked earlier 'what's on the server to receive the data?' A: simple text file. Same folder.

Thanks, L P B

Re: Transfer to/ from html5 standalone and text file

Posted: Mon Apr 20, 2020 3:28 am
by FourthWorld
LeProfBard wrote:
Mon Apr 20, 2020 3:16 am
FourthWorld: you asked earlier 'what's on the server to receive the data?' A: simple text file. Same folder.
Sorry, I wasn't clear: what software is running on the server to handle the write? And how does it handle authentication?

Re: Transfer to/ from html5 standalone and text file

Posted: Mon Apr 20, 2020 10:37 am
by mrcoollion
Maybe publishing your desktop application as is, instead of making it a web version is an idea.
https://smartbear.com/blog/develop/take ... in-15-min/

Re: Transfer to/ from html5 standalone and text file

Posted: Thu Apr 23, 2020 4:18 pm
by LeProfBard
Hi Richard,
Thanks for asking your question, it pointed me in the right direction. I was first able to set up the 'write to text file' via PHP, but I'm pursuing it in .lc, just not quite there.
Thanks to all for your responses.

Re: Transfer to/ from html5 standalone and text file

Posted: Thu Apr 23, 2020 5:00 pm
by Wally
I just started a new thread before I saw your just posted response in this thread. See: https://forums.livecode.com/viewtopic.php?f=120&t=33981

If you can share about the PHP or .lc, we would all be thankful!

Re: Transfer to/ from html5 standalone and text file

Posted: Thu Apr 23, 2020 5:35 pm
by LeProfBard
Hi Wally,
Sure. Here's what worked for me in PHP. I'm still hacking away on finding the LC equivalents, though.

<?php
$chiffre = ($_POST["nextNumber"]) ."\n"; //receives new number, adds CR

$file = 'numbers.txt';

file_put_contents($file, $chiffre, FILE_APPEND | LOCK_EX); // Appends, locks file from multiple write attempts
?>

Re: Transfer to/ from html5 standalone and text file

Posted: Thu Apr 23, 2020 5:38 pm
by LeProfBard
oh, BTW, I ended up using tsNetPost with callbacks, as per :
http://lessons.livecode.com/m/4071/l/69 ... -callbacks

L P B

Re: Transfer to/ from html5 standalone and text file

Posted: Thu Apr 23, 2020 6:13 pm
by Wally
L P B,

Thanks for the info.

The LiveCode user guide says:
"Two important unsupported features are unlikely to be added in the near future:
operations that need to pause the script while something happens (e.g. wait 10 )
externals (including revdb)"

Isn't tsNetPost part of an external?