Saving txt file

536 views
Skip to first unread message

j p

unread,
Oct 21, 2011, 3:47:13 AM10/21/11
to Processing.js
Hey everyone I want to save a txt file with some data from my program
on the server that the app is on. I tried using saveStrings but it
doesn't seem to work, as no file seems to be created.

This is an example of what i'm trying to do:

void setup()
{
size(200,200);

String words = "apple bear cat dog";
String[] list = split(words, ' ');

// now write the strings to a file, each on a separate line
saveStrings("nouns.txt", list);

}

void draw()
{

}

Alternatively is there another way I should be saving a txt file to my
server?

Benjamin Gudehus

unread,
Oct 21, 2011, 7:48:44 AM10/21/11
to proces...@googlegroups.com
Hi!

Unlike Processing for Java Processing.js has no method saveStrings(), since saving files in the browser is
not allowed. Firebug shows in the console, that an ReferenceError is thrown.

> saveStrings()
ReferenceError

You could send the data to your server with an AJAX request. Have a look at this jQuery function: 

$.ajax({
  type: "POST",
  url: "some.php",
  data: "your file contents",
}).done(function(msg) {
  alert("Data Saved: " + msg);
})

Greetings
Benjamin

2011/10/21 j p <jp2...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Processing.js" group.
To post to this group, send email to proces...@googlegroups.com.
To unsubscribe from this group, send email to processingjs...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/processingjs?hl=en.


Benjamin Gudehus

unread,
Oct 21, 2011, 8:04:57 AM10/21/11
to proces...@googlegroups.com
Sorry, I have to correct this. There is an method called saveStrings().


p.saveStrings = function(filename, strings) {
  localStorage[filename] = strings.join('\n');
};

It seems that it uses the LocalStorage-feature from HTML5. Does the browser you tested this support HTML5?


2011/10/21 Benjamin Gudehus <hast...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages