Logic Machine Forum
Help with the use of storage.set and storage.get - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Help with the use of storage.set and storage.get (/showthread.php?tid=5039)



Help with the use of storage.set and storage.get - legolas2069 - 18.10.2023

Hello, I'm testing the use of storage function to first understand it, and then visualize some data with JS functions.


First, I write some data in a variable and I storage it:
Code:
data = {1,2,3,4,5,6,7,8}
storage.set('/user/example.lp', data)

Second, I read this data and I log it for viewing the result:
Code:
store = storage.get('/user/example.lp', {})
log(store)

After that, I try to view it on a browser console, for which I use custom JavaScript (the first console.log it's to see that is working):
Code:
$(function(){
console.log('Hello');
  $.get('/user/example.lp', function(exampleData) {
           console.log(exampleData);
           });
});

But I received a 404 code for the GET, and it says: Not found.

What am I doing wrong?

I've also tried to explore the user folder with Filezilla, but it's empty.

Thank you for your help.


RE: Help with the use of storage.set and storage.get - admin - 18.10.2023

Use FTP to upload .lp files. Storage is like a database, it does not store data in separate files in the filesystem.


RE: Help with the use of storage.set and storage.get - legolas2069 - 18.10.2023

(18.10.2023, 10:09)admin Wrote: Use FTP to upload .lp files. Storage is like a database, it does not store data in separate files in the filesystem.

Understood. How can I do it? I figure this, but I'm not sure It's ok

Write to FTP:
Code:
data_ftp = {8,7,6,5,4,3,2,1}
io.writefile('example.lp', data_ftp)

Read from FTP:
Code:
data_ftp, err = io.readfile('example.lp')
log(data_ftp, err)

Custom javaScript:
Code:
$(function(){
  console.log('Hello');
  $.get('example.lp', function(exampleData) {
           console.log(exampleData);
           });
});

And the same error code 404, not found. In Filezilla I don't find it. 

I tried to look for it in the forum using search, but I didn't find it.

Thank you.


RE: Help with the use of storage.set and storage.get - admin - 18.10.2023

You need to use absolute paths. In Lua code use /www/user/example.lp instead of example.lp. In JavaScript code use /user/example.lp instead of example.lp


RE: Help with the use of storage.set and storage.get - legolas2069 - 18.10.2023

Done and it works, thank you!