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);
});
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 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.
I have a program that uploads files to a ftp server. If upload is complete then I delete the files. Occasionally the files are not deleted and because the upload is automated I get an infinite loop where 100 copies of the file reach the server. If I try to manually delete the file from explorer I'm able to do it but for some reason the Deletefile command from my app doesn't work.
I've tried raising last OSError and I get nothing.
The files are stored on a mapped drive. Is there any workaround? If I upload 30 files to a ftp server sometimes one or two files cannot be deleted after loading them to the server.
Is there any way to close the file even if it is opened from another program? Something like unlocker does?
How can i see if my application is locking the file? I haven't implemented any locking mechanism inside the app.
Thanks.
When uploading files to a server and calling a controller method does a HttpPostedFileBase contain the entire file or just information such as name, path, etc?
What I want to know is if the file is uploaded to the server right away or not until calling SaveAs(path) ?
As the file is part of your request, it is uploaded immediatly. It is just buffered into a tempfile which the system will delete once you send the Response.
If you use SaveAs, you just transfert the file into a permanent location.
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.