Remote form - XLSX download - javascript

I have a form, where user can select values from collection of check boxes to filter data. Form posts to controller where xlsx format is defined to download xlsx file. I am using axslx_rails.
Now, I would like something to happen before and after the remote call.
And it works ok.
What I can't figure out is how to actually download a xlsx file as the respond block goes to JS format, not xlsx, which is something liek this:
format.xlsx { response.headers['Content-Disposition'] = 'attachment; filename="test.xlsx"'}
So, it works either one or the other way. Non-remote form downloads file as i have a format: xlsx defined. If i do a remote form, javascript works (show spinner, hide spinner, etc...), but file is not downloaded.
How can I achieve both?
Thx

OK, i've given up and went with a solution:
to save file to disk (to some publicly accessible location)
download file via jQuery fileDownload plugin
delete file
Seems like the best solution currently for what i need.
If someone has a more elegant solution, without extra JS library involved...

Related

Download multiple files using httpservlet

I am trying to implement a function where on a page like this you first select the records to export/download, after clicking download button and fetching records from db, the information will be saved in two ways:
for text info, they will be written in a xls file together and then downloaded
for pics, they will be packed in a zip file first and downloaded.
Front-end request is formed in this way
var form = $("form");
form.css(...)
.attr("target","_blank")
.attr("method","post")
.attr("action","export")
....
.submit()
For back-end, I used HttpServlet with some routine operations like
response.setContentType();
response.setHeader("Content-Disposition","attachment;filename"+fileName+".zip");
out = response.getOutputStream();
out.write(buffer,0,b);
in zip download, also ZipOutputStream was used like
zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()))
...
zipos.putNextEntry(new ZipEntry(...))
When I test the two downloads separately, it worked fine for excel but for Zip file I was shown error like this.
When I tried to test with two form.submit() requests, only the first one will be responsed.
Here are my questions:
What's reason for error in zip file? I tried to setContentType to "multipart/form-data","zip","gzip","application/octet-stream". Neither worked.
Does my way for two sole requests make sense? What's the best way to realize the two/multiple file download functionality?
Thanks.

Proper way to export HTML table as Excel file?

What's the correct way to export an HTML table as an Excel file so that the user can click a button and download the Excel file (ideally using Angular and without using server)?
I've seen many answers like this:
Export to xls using angularjs but doing this gives an error similar to the following:
"The file format and extension dont match... The file could be corrupted..."
and I believe the file is actually in HTML or XML format, not actual Excel.
The warning does not present a good image to the user.
What's the right way to actually export a file as Excel without using the server?
Or is the server required to create the file?
If you are just using tabular data, then I would argue that the best solution would be building a CSV file. This could be natively opened by excel and converted into an XLS file if necessary. You can do so by arranging your data with a data URI. The octet-stream will force a file download rather than opening in browser. Here is an example:
CSV

how to use own file process handler on blueimp jQuery File Upload?

I got my own PHP image file upload process handler. I was just looking for a jQuery solution to optimize upload bar and multiple file selections. So I spent some hours to get into jQuery File Upload - no ui, basic setup. I did all the js changes I need and tried to implement it to my existing file upload form.
But now I realize, the /server/php/UploadHandler.php is nessassary to the jQuery scripts. Without this php file, I don't get to the "done" event.
I don't want to make use of the file processing UploadHandler class, because I got a lot of own steps, like watermarking, that needs to be processed on uploaded image files. I like to do something like this:
done: function (e, data) {
// alert('done!');
document.upload.submit(); // existing upload form including jQueryFileUpload
},
How do I get rid of the file processing in this PHP Class? I just want "jQuery File Upload" to offer a nice multipart file selection, a jQuery image preview and it's great processing bar.
Is there a way to stop PHP touching files?
I had a similar issue. We wanted a file upload inside an HTML form along with some other data, not a simple upload. For this the provided PHP class isn't sufficient.
You can write your own PHP upload handler easily, use the provided one as reference. Or use some other backend technology. Important was to use the url to the backend upload handler as the form action.
In the JS you have to overwrite the "add" Option of the fileupload widget, if you don't want to submit immediately. "done" is only useful for evaluating the result.
We saved the data inside the add handler in a closure variable and used it to submit, when the user wants to submit. By this the other form data is sent with the upload request automatically. Like this:
(function()
{
var uploadData;
$("#uploadInput").fileupload(
{
add : function(e, data)
{
uploadData = data;
},
... other options ...
});
$("#submit").submit(function()
{
if (uploadData != null)
uploadData.submit();
}
})();
Not sure if that works for multiple uploads, but I hope this helps.

Need to do bulk file upload in JavaScript

I have a little bit of an unusual situation I guess. I have a page for placing new orders and part of a new order is a variable (0-n) number of files that are to be uploaded and associated with the order on the back end. The user also needs to specify a description for each file.
I've used a couple jQuery upload plug-ins with great success, but in this case I'm not looking to upload a single file when the user hits "OK." What I really need to do is upload a file by passing a local path to some method that will do the upload.
Does anyone know of any plug-ins that do this?
Thanks!
Ajax Uploader could be helpful? I believe it allows multiple uploads.

how to display file dialog with csv streamed from a server

I am using jQuery.doGet() to get a csv file from the server. I am receiving the contents of the file in the onDataReceived function. How do I display the file dialog for the user to save it?
adsafe.util.doGet(url, params, onDataReceived);
onDataReceived(data) {
// how do i launch the file dialog for the user to save this data as a file.
}
Just today I did something similar but I just use window.open(file) and then issue the download in the new file.
I found a solution to this.
Instead of using doGet and then trying to launch the save box myself, I left it to the browser to do everything.
Simply calling
window.location = url
So this, downloads the file and displays the file dialog box.
Is this the right way to do it? Any comments?

Categories

Resources