Transfer to/ from html5 standalone and text file

Bringing your stacks to the web

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Transfer to/ from html5 standalone and text file

Post 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
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post 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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by Klaus »

Hm, I thought he wanted to let the HTML5 runtime write a file on the SERVER!?
Not? :D
LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Re: Transfer to/ from html5 standalone and text file

Post by LeProfBard »

Yes, it's on the server, not on the client/user's file system.
Thanks,
L P B
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by FourthWorld »

What is on the server to receive the data?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Klaus
Posts: 14324
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post 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)
LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Re: Transfer to/ from html5 standalone and text file

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Transfer to/ from html5 standalone and text file

Post 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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

Re: Transfer to/ from html5 standalone and text file

Post 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/
LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Re: Transfer to/ from html5 standalone and text file

Post 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.
Wally
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Jun 15, 2008 4:51 pm

Re: Transfer to/ from html5 standalone and text file

Post 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!
LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Re: Transfer to/ from html5 standalone and text file

Post 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
?>
LeProfBard
Posts: 17
Joined: Thu Mar 26, 2020 8:23 pm

Re: Transfer to/ from html5 standalone and text file

Post 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
Wally
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 46
Joined: Sun Jun 15, 2008 4:51 pm

Re: Transfer to/ from html5 standalone and text file

Post 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?
Post Reply