Save a file after a perl script runs on a web page - html

I have a web page that will be used to create KML Files with a perl script.I want the user to add some data to a form that will be used in my perl script. When the form is submitted it will run the script, create a kml file, then prompt the user to save the file. The only part I am not sure about is how to have the user save the file after the script has created the KML. Do I have the perl script prompt the download or use something on the HTML page prompt the download. I am not sure the best way to do this.

If you have a link or a form for telling the server to build the KML then just generate the KML normally and send it back to the browser with some extra HTTP headers. The headers you want are:
Content-disposition set to attachment;filename=whatever.kml where "whatever.kml" is what you want the file to be called.
Content-type set to application/vnd.google-earth.kml+xml.
The Content-disposition should tell the browser to download the KML instead of trying to handle it.
So the Perl script will be prompting the browser to prompt the download.

Assuming the contents of the kml file are in $kml then you'd want to do something like:
use CGI;
my $cgi = new CGI;
print $cgi->header('-Content-disposition' => 'attachment;filename=kml.xml',
'-Content-type' => 'application/vnd.google-earth.kml+xml');
print $kml;

Related

Published https://docs.google.com/spreadsheets redirects to other URL (CSV data)

We auto-publish a Google Docs Spreadsheet (one tab as CSV). Google docs is providing a fixed URL that refers to the CSV. We import this CSV in another tool for product data import.
Suddenly this URL is redirected by Google Spreadsheet. If we go again in "File/Publish To The Internet" we can the same URL for that CSV.
Question: How can get the URL without redirection again?
Error: Source file
https://docs.google.com/spreadsheets/d/e/2PACX-1vTQsBEmvOwFwxORMqYg2N6LzzYqdqsdDCjxqsdqsdH72gdMCP4xrs1lsN37RO4h1-rjJsQ/pub?gid=501162839&single=true&output=csv doesn't exist (HTTPS : File not found ! (HTTP/1.0 307 Temporary Redirect)). Please check the source file path.
In short, the collection process needs to follow the Location header. Depending how you're getting the CSV this might be simple or a pain. I collect CSVs using curl so just adding the -L switch is sufficient to make sure the incoming files are the CSV we're looking for instead of the HTML that we were getting without -L. Without knowing what utility or process you're using to download the CSV I can't be more specific, unfortunately.

Can I have a link automatically download a file in an email?

I have an email with a link to a video file stored on a cloud hosting service (backblaze)
I'm trying to make it so that when someone can clicks the link the file would start to download. Right now I have this:
Download Here
That takes you to the video instead of downloading the file. I'd like to avoid that if possible and have the link prompt you to start downloading the file when you click on it.
Is this possible to do in an email when the file is stored on a server somewhere?
Thanks
I think you can't do this in plain html.
Since you can't use JavaScript in email, the best option would be to manage to include some PHP script in the server that do the job.
This example was taken from serverfault
PHP
?php
// We'll be outputting a MP4
header('Content-type: video/mp4');
// It will be called downloaded.mp4
header('Content-Disposition: attachment; filename="downloaded.mp4"');
// Add your file source here
readfile('original.mp4');
?>

Saving web page as an html file on computer

I want to save the source code for my website page into my computer. I know that I have to use an http request to download the source code for my web page into the computer as a html file. I want to run a diff to track changes between two html files for a web page. I am wondering how to implement a program to perform the function of saving a web page as an html file on my computer. Please help it is really appreciated. I want to solve the problem programatically. I was researching on this topic and found that httpget, and selenium scripts can achieve this task but I am struggling with the implementation.
With linux you can just use wget.
wget http://google.com
that will save a file called index.html on your computer.
Programmatically you can use python:
import urllib2
# create a list of urls that you want to download
urls = ['http://example.com', 'http://google.com']
# loop over the urls
for url in urls:
# make the request
request = urllib2.urlopen(url)
# make the filename valid (you can change this to suit your needs)
filename = url.replace('http://', '')
filename = filename.replace('/','-')
# write it to a file.
with open(filename + '.html', 'w') as f:
f.write(request.read())

How can I use File API ando/or BLOB to upload a file using a regular HTML form?

I have a strange situation, I need to run a custom criptography on a file in the moment that the user choose the file to be uploaded.
To achieve that I am running an Applet to crypt the file at the onSubmit event, but once I get the the crypted string from the Applet how can I send that as a regular file upload?
Is there a way to create a blob and then attach it to the file input?
I dont'have access to change the application source code, everything that I can do is write a custom Javascript.
Any help would be appreciated! Thx!

How to call a perl cgi script from another perl cgi script

I have a html form ... While submitting that form, I am calling one Perl CGI Script, that will save the data in MYSQL database.
After saving the data in databse, i want to reopen the same page with all empty fields in form, means i want too reload the same form again.
How can i achieve this? or what should i call in my script so that i can come back to same form again.
Remember i am generating the forms using template and perl script..
Thanks in advance
You can redirect using HTML's meta refresh or by using JavaScript's window.location object. Have the CGI script output any of those.
Another way is to have the CGI script output a redirect header. You can use CGI's redirect method for this, or output it manually.
Is this second program really a CGI program? I mean does it accept parameters from a HTTP request and return it's results in an HTTP response?
If that's the case then you can call it using libraries from the LWP CPAN distribution.
If your second program is actually just a command program then you can call it using system.