I have a ajax download functionality in my MVC webapp.
User can select a criteria and click on export button. Internally it will fetch data and return an Excel file. up to this functionality is working fine.
But the issue occurs, While one download process is running and now user changes the filter criteria and again click on export button. Now two download processes are running. Whichever process completes first will return file to download. Now the user can see Open, save, cancel option to download first file. As this stage when second download request is also completed and returns file to download. When I opens one file the another file download option is also lost.
Initially I thought it might because both the files are having same name. So I made changes to set unique file name for every request. But It still gives only single file to download.
Can anyone help me on this?
edited :
On other pages where I have two different types of files to download, the above functionality works successfully.
In none ajax requests, page can only be waiting for one response.
In order to solve that problem and wait for multiple responses you should use target attribute with value "new" as the following code depicts:
Your download Text
The above code makes each response to be downloaded in a new tab.
Related
I have a create action in a controller that is in charged of uploading Excel files. Some of these Excel files take a long time to process. Once the Excel file is validated and the content of the file is saved in a table, the user is redirected to another view where they see a success flash notification.
I would like to alter this process but honest to gosh I would love some guidance or perhaps a link to something similar.
1) I am trying to make it so, once the create button is selected and the validations pass, the user is redirected elsewhere and once the file upload is completed, the user will be notified regardless on where they are in the application.
2)While an excel file is being processed, the create option is not available to any other user. (Currently, if the file is being processed, it stays in the new view and if you keep clicking on the create button, it processes the file over again prolonging the uploading process)
Thanks in advance for the help!
From my point of view you should do following steps:
1) Create a special storage for states (global place where information about file upload status is stored). I propose to use key-value storage such as redis or memcached
2) When user upload file you save it to the disk, queue background job (resque or delayed_job) and set flag file_is_processing to true
3) In your views disable button if file_is_processing flag is set.
4) In background job you validate file and if it is not valid set a flag in storage not_valid_file & remove file_is_processing flag
5) Have before action where you check this state and if file is not valid redirect user to file upload page with notice & remove not_valid_file flag.
6) If file is valid you parse file then remove file_is_processing flag & set file_is_processed
7) In before action redirect user to success page, show notice & remove file_is_processed
Seems to be easiest way for me.
I am trying to use resumable.js for my application for file uploads. It works fine and uploads the file.
Problem occurs if after a file is uploaded successfully, I try to select or drop same file again, it does not trigger the file upload(r.upload()) till i refresh the page.
Is there any way to clear file list from resumable obkect after all files are uploaded so that they can be selected again?
Also is there a way to introduce some delay(like sleep(5)) before sending another chunk to server.
In the fileSuccess event you can call r.removeFile(file); to have the file removed once completed. This will clear the queue as you go and should allow you to upload more files. I suspect the reason it is not firing the upload() event is that you have reached the max files limit and refreshing the page clears the queue.
Should look something like this:
r.on('fileSuccess', function (file) {
r.removeFile(file);
console.debug('fileSuccess', file);
});
Often some validation factor with nothing to with the file will cause a server side validation error, and reload the page. The previously chosen filename is always missing, and the poor user has to select the file again. This is especially frustrating when they fix the other error and click Submit again, thinking all will be all right.
Can I not somehow persist the file name in my model and set it on the 'file' input when the page loads?
Every form submission requires complete file upload, so to not make user poor, you should store file on server even when validation fails. When you do it, you have list of already uploaded files on the server ready for next, proper form submission. You can also present box with already uploaded files in view.
For security reasons, manipulating file upload field is not possible.
I have a slightly weird file upload user flow in an application I am testing which causes the file upload dialogue to remain open when testing with selenium-webdriver, via capybara.
The flow is this:
User is presented with a choice of 3 buttons (to specify type of file to be uploaded)
Selecting any of these immediately triggers file upload to be shown (via js)
Choosing file inserts the filename in a hidden field and submits form to the server
The problem is this: I can click the button for step 1, and attach the file for step 3, and all continues as usual. But the system file open dialogue remains open due to step 2, and these accumulate if I'm running several scenarios on the same piece of functionality.
So, although this doesn't break anything, it is obviously a bit untidy potentially having several file upload dialogues persisting through the entire test suite.
Have you tried skipping step 1 and 2 and just doing step 3?
Just wondering if that would work (can't say I have tried this before)
As it takes some time to prepare the content of the data to be downloaded, I want to show a message "Preparing file to download" when the user submits the request
Then when the file is ready, I use send_file to send the data
Once it's done, I need to clear the message
Thanks a lot
Here is what I would do.
1. Create a prepare_file action
First, I would create an action whose job would just be to create the file and rather than rendering HTML, it would render a JSON object with the name of the file that was created.
2. Use AJAX to call the prepare_file action
On the client, when the user clicks to download the file, you display the message, "Preparing download..." and just do an AJAX request to that action. The response you'll get back via AJAX is the name of the file created.
3. Redirect to the file download
Finally, you can hide the preparing download message and redirect the browser to the file download via JavaScript with the name of the file that was created. You would use send_file in this action.
I know that, in the question, you also wanted to be able to display to the user a message when the file is downloading and another message when it is finished. However, this isn't possible unless you write your own client-side download manager. The browser handles file downloads entirely and the user will see in the browser that the file is downloading and what the progress is. So, I understand where you're coming from, but you shouldn't feel like the user isn't being informed of what's happening.
At least with this solution, you're displaying a message to them when the file is being prepared and then once that message disappears, they'll get the download file dialog from the browser.
If you need help with actual code samples of how to do this, let me know.