Transfer to/ from html5 standalone and text file

Bringing your stacks to the web

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

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

Transfer to/ from html5 standalone and text file

Post by LeProfBard » Sun Apr 19, 2020 5:06 pm

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: 11813
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by Klaus » Sun Apr 19, 2020 5:27 pm

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: 7713
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by FourthWorld » Sun Apr 19, 2020 5:37 pm

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
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Klaus
Posts: 11813
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by Klaus » Sun Apr 19, 2020 5:51 pm

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 » 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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7713
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by FourthWorld » Sun Apr 19, 2020 6:44 pm

What is on the server to receive the data?
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

Klaus
Posts: 11813
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by Klaus » Sun Apr 19, 2020 6:47 pm

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 » Mon Apr 20, 2020 3:16 am

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: 7713
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Transfer to/ from html5 standalone and text file

Post by FourthWorld » Mon Apr 20, 2020 3:28 am

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
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

mrcoollion
Posts: 548
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Transfer to/ from html5 standalone and text file

Post by mrcoollion » Mon Apr 20, 2020 10:37 am

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 » Thu Apr 23, 2020 4:18 pm

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: 43
Joined: Sun Jun 15, 2008 4:51 pm
Location: Albany, NY

Re: Transfer to/ from html5 standalone and text file

Post by Wally » Thu Apr 23, 2020 5:00 pm

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 » Thu Apr 23, 2020 5:35 pm

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 » Thu Apr 23, 2020 5:38 pm

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: 43
Joined: Sun Jun 15, 2008 4:51 pm
Location: Albany, NY

Re: Transfer to/ from html5 standalone and text file

Post by Wally » Thu Apr 23, 2020 6:13 pm

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

Return to “HTML5”