capture and save string to local file - angularjs

I have a very simple app with which I want to capture a string and save it to a file within the app directory. Is it possible to use $http to post/put to a file within the app tree similar to how you'd get static files like views?
Thanks
C

Use HTML5 filesystem API. Example here.

Related

problem when read files from local computer in pyscript

When I run the Python file, the file works correctly, but when I run the Python file with the script, it gives an error in read txt file(file not found).
how can i solve this problem؟
Software written in any language (Python, JavaScript, WASM) cannot access local files directly. This is a browser security restriction. The browser can access files on behalf of your application using the <input type="file"> DOM element link.
In Python and JavaScript, you must provide the user with a file input selector. The user selects the file and your application can the retrieve the file data from the browser.
In JavaScript this functionality is implemented with the FileReader class. This class can be used in Python via the create_proxy() function to proxy event callbacks.
If you are just getting started with Pyscript, I have written a number of articles link.
See this issue report.
Code running in a webpage is sandboxed and can't freely access files on the computer hosting the browser.
(It would be a terrible security problem if just visiting a webpage would give the author of the page access to your files).
If you want to access a file on the user's computer, use <input type="file"> and have the user select it. I don't know if you can access it directly or if you would need to use a JavaScript FileReader and then pass the results from JS to PyScript … but one of those two approaches should be possible.

How to store files in MongoDB using Node Js and AngularJs?

I am weak in coding so I am asking this type of question. I've read similar questions but could not find out the solution to my question.
All I want is to store the actual word or pdf file (and not links) in the MongoDB using NodeJs as backend and AngularJs as frontend.
I've read that GridFS is used for this but I could not figure out how!
Ok... Firstly you cannot save a file in MONGODB, only text. Thus what I do is save the path to the file. For example: src: "/uploads/pdfs/pdf1.pdf". Save the file in node JS using https://github.com/jacoborus/node-filesaver . Slim example of what I would do: http://pastebin.com/huvCknWb

Generate new file using angularjs

I have certain html forms. On-submit it has to generate new text/json file (name to be saved based upon one of the field in form) in the local drive with the contents filled in the form. Is this possible in angularjs? As well as to retrieve the data based upon the file name.
Spontanously, I wouldn't want a javascript based web page to access my hard disk drive. That seems like a security risk for me.
Could local storage be an alternative for your use case?
Read more about local storage and angular js: http://www.amitavroy.com/justread/content/articles/html5-local-storage-angular-js
You can use filesystem API but it is chrome specific.
Check this Exploring the FileSystem APIs

Change Angularjs existing backend to Play 2

I have a fully developed Angularjs frontend app (with the routes and everything set up) and would like to change the current backend to a Play 2 Java. What is the best approach to display the existing html files from Angular in Play? I have found a few examples of how to connect the routes, but I would rater not create an index.scala.html file as I would like to have the two frameworks separated as much as possible and having Play only working as backend.
If you don't want to dynamically generate views from Play using Twirl and you just want to serve your HTML static files publishing them as assets is the way to go. By default assets are designed to provide resource like CSS or JS files but nothing prevents you from serving ordinary HTML views as well.
Simply put your index.html in the public directory and modify the conf/routes files so it can handle all requests:
GET /*file controllers.Assets.at(path="/public", file)
This way your index.html will be accessible at www.yourdomain.com/index.html. Remember to put this line as the last mapping in the file as it matches all possible URLs. Other services should be declared above it.

Angularjs: write json data to file

Simple question, is it possible to write json data (received from API) to a json file in my directory structure. The api returns a json string. Is there any method in angular that supports this or do I need to rely on jquery? Extra information on this topic is welcome.
You cannot access the user's filesystem from javascript, instead you should present the user with a save dialog (it's up to the user where to save the file). AngularJS doesn't support this out of the box, you could however save a file to the default download folder by converting the JSON to a base64 string and bind it to an a href.
<a href="data:application/octet-stream;charset=utf-16le;base64,ew0KICAgICJnbG9zc2FyeSI6IHsNCiAgICAgICAgInRpdGxlIjogImV4YW1wbGUgZ2xvc3Nhcnki
IA0KICAgIH0NCn0=">json file</a>
For more control to save files to the client, you could use FileSaver which has support for older browsers.

Resources