Creating a text file from button press with Flask and AJAX - html

I need to create a text file from a web application.
I want to use Flask, and I assume I'll need to use AJAX, but hosting a server and having the text file created server side sounds nice.
Essentially I want to fill out some forms on a webpage (closed network) and have the values from those forms populate a text file that gets saved on the server's local machine.
I have tried originally launching a python script on server side within Django, but my needs have changed, and now all I need to do is create a text file that can be utilized by another system.

Related

How to read a text file, parse it to a web interface and store changes

I am looking for a way to read an unformatted UTF-8 text file from disc and parse its content to fields on a web page / web interface, allowing a user to make edits and in return, store these edits to the text file.
The text file and the web interface will be running on a Raspberry Pi 3. I am very new to this, so I'm basically looking for any starting point or even hint, if my approach is heading in the right direction.
As for now, I have considered using Node.js with the File System Module, which unfortunately only gets me as far as reading the text file. My question therefore mainly aims towards:
is node.js the right approach for this scenario?
if so, how can i parse individual blocks of this text file to a web interface and ...
... store edits on this web interface back to my file
thanks a lot

Nodejs/Express Save select avatar from web client and save directly to MySQL Database

Looking for some guidance here. I am building Nodejs/Express app with MySQL Database. I want to be able to click on the users image on the web page (initial image is generic), select a different image and upload/save new image into MySQL database. I using:
$('#file-input').trigger('click').change (function(){
alert($('#file-input').val());
})
I get C:/fakepath... for image location. I would like to how to upload/save selected image to the MySQL database. Connection to database is established, and routes for regular data work just fine.
Before answering your question will suggest you to not save image into your MySql or any database, use IPFS, local application directory/folder, or best AWS s3 bucket.
You can use busboy.js NPM module or multer.js NPM module for file upload to server, there's lots of good reason to not save any kind of file in local database.
Now back to how you can save image in database. You can do so by first converting your image to a data format your MySql understand. By default image is binary and depending upon image selected some image binary is so big that even MySql text datatype is small for them. Converting binary to hexadecimal does help but still too big for MySql text datatype. Also you will need multipart/form-data for file upload.
You can easily find "How to upload file in nodeJs?" in a google search. Still if need an example here's one "Upload file using multer.js"

is it possible to save data from a html form to an excel file with web services?

I have made a newsletter with html and CSS, and in that newsletter I have 4 text boxes which takes the users name,family name,phone number,email address.Can I use a web service to transfer this data from the HTML form to an excel file, or a database on a host?
Is it possible at all? saving data from a html form to an excel file with web services?
If yes, how?
First of all, I assume you save this data into a database. That would be my approach at least.
So:
Send the data using a form to your server application (ASP.NET or something alike);
Save it in the database (or process it right away);
Then use a package like EPPlus to generate the Excel file in a web service. See their project page about the how to do that;
Return the result to the client.
yes thats possible but you would need a fifth button like send information that would post those fields to a php script on your server and then save it into your database
look here to see how to post information to your server
http://www.w3schools.com/php/php_forms.asp
and here for a small mysql tutorial
http://www.w3schools.com/php/php_mysql_intro.asp

Downloading and replacing file in package

In my Visual Studio 2013 Solution, I added a folder "mAppData" with some static Content for the app.
One of the files is a Textfile ("imprint.txt").
On a phone page, I Display the content of this file. This works fine.
Is there a way to replace this file on runtime? I want to download new Content from web and replace this file with the downloaded content.
rather than downloading and replacing the "imprint.txt" you could simply download the imprint as text (from your imprint.txt - stored online) and display it:
var client = new System.Net.WebClient();
client.DownloadStringCompleted += (sender, args) => MessageBox.Show("downloaded imporint: " + args.Result);
client.DownloadStringAsync(new Uri("http://yourSite.ch/imprint.txt"));
My sample simply shows a MessageBox with the downloaded text. However, you can update a text control or similar.
If you want the content to be available even if you are temporary offline, you can store the file in the filestorage.
Consider adding multiple files for different languages in your build and load the file depending on the localization of your phone.
However - replacing a existing file for your Solution is not allowed on runtime. Consider this as a safety feature. If the Codebase of your app could change during runtime, your code would be injectable by an attacker.
You can't alter the package content at runtime, it is read-only.
The place where you can store data locally is the Isolated Storage. What you should do is create a file in the Isolated Storage at first launch that stores the original content of your file ("imprint.txt") and then you'll be able to change it any time you want.
Here is a tutorial that explains how to read and write text in the Isolated Storage: All about WP7 Isolated Storage - Read and Save Text files

HTML 5 - load text from text files

I am facing problem in HTML 5. I need to statically load data into web page from local saved files. Up to now, I have been only able to load data via < input type="file" id="fileinput" / > but I want to load data from static location, which never changes. How to do that? And is there any way how to determine, whether some local file was changed from previous version?
Thanks
no, this isn't possible if by 'local', you mean a file at /home/waypoint/somefile.txt. You can make a 'link' with the filesystem api (if you selected it in an input field, for instance), which is valid to do computations with it (to read it, write to it, display it in img,etc). But it is deleted/unvalid, as soon as the window closes. If you could just magically "read" any local file via javascript which resides on the file system, who would stop google to read out your /etc/passwd file?
if your local computer is also your server and therefor your server-side code has access to the local file /home/waypoint/somefile.txt, your app can get it via ajax. Checking if the file exists, would be done the same way.