Background File Copy process in ASP - asp-classic

I have an application in classic ASP. On click of a button, it copies a file and its relative folder from one folder to another folder, and displays a link to user for the destination folder. User can click on link and get the file from destination folder. Now, I am facing problem with file and its relative folder size. I have some of them with size greater than 500MB. So, copy process takes so much time that my application gets Time Out error. **Is it possible to create some background process for copy? and when process completes it should fire some event. **
Cheers

This is a pretty lame solution, but a solution nevertheless: you could fire off an Ajax request to a separate ASP script to do the copying, and just put a really long timeout on that script. When this completes, it could, of course, update the calling page with an alert or notification to the user, but that very much depends on the user having enough patience to keep that browser window open.

The options I tried are,
Executing copy command from Shell, not effective because ASP page waits for shell command to finish.
Creating a trigger in SQL database which gets fired when a new row gets added into the table, and then copy the files and send an email to user using TSQL. This affects my overall database performance.
AJAX solution also waits for process to end.
Now the solution I have implemented is, ASP page just creates a request and displays a message to user that user will get an confirmation email, then I created a small windows application which keep on watching for any request generated by ASP page, and as soon as any request comes in, it starts copying the files and at end sends as email to user as confirmation.
This solution is working for my requirements, please do share if you have any better and robust solution for the scenario.
Cheers.

I thought of another idea. I'm not sure of the exact way to do this on an IIS server, but if I were running on a Linux server, I would set up a cron job to run a web script every 5 minutes or so. The script would check for new files and perform the copying. Since copying could take more than 5 minutes, you would probably need to keep track of files in an XML file or db or something.
This would free you from writing/maintaining a separate Windows desktop app.

Related

Looking for a way to track a True Download of a file, not just the fact that they clicked on a file link

As I understand it, when a link to a file is clicked in the browser, the file is silently downloaded to a temporary directory on the computer. Then the prompt is displayed which shows Open, Save, Cancel... Then if the user clicks Save, they are prompted to save it somewhere, and finally the file is basically transferred to that location when confirmed.
Assuming that is correct, I'm looking for a way to determine if the user actually downloaded the file. So basically determine if they clicked the Save button.
The bit of research that I've done leads me to believe this is not possible, because there is no standardized way of capturing that event, however I could be wrong. And the only possible solution I can come up with is to create an actual client application. Any thoughts on that?
Also, if there are any other off the wall ideas, I'm open to those as well.
And in case it makes a difference, I'm working within an ASP.NET environment.
How about turning this whole problem around and audit the file that actually being downloaded. You can turn on file/folder auditing and capture onlyt the success and failures of the IIS process. Then correlate the audit event with the pieces parts in the IIS log to get the particulars of who actually downloaded the file.
Just my $0.02 YMMV

Can I preserve files input at Meteor hot code push?

Background: I'm working on file uploading in Meteor.js, when I do a hot code push the client refresh their pages, but if they are during a file upload this stops.
My question: "Is the Meteor hot code push a total refresh of the app?"
If so then I'm out of luck, since the file input cannot survive in a session/cookie.
but:
If not then how can I recieve hot code push event? (is there a Meteor.addListener for this?)
(no, I dont have any code since this is a general Meteor.js question)
The way hot code push works is it serializes your application state and refreshes the page, then restores the state. Unfortunately, file uploads are a little complicated. I imagine you're not actually storing the file upload progress in your app state, which means that if the page refreshes, it won't start up again all by itself and continue.
To fix this, you could first store the uploading file locally in a database and upload it from there. Keep track of how much has been uploaded, and then when the app refreshes, tell the app to continue from where it left off.
Obviously this is a non-trivial problem. Personally I would probably consider this an edge case and ask the user to re-upload the file rather than investing all the time needed into engineering a solution. Unless your app use case consists entirely of uploading files, at which point you have a challenge on your hands :-)

Does FileSystemObject know that a file is incomplete?

Yes, I'm still using Classic ASP.
I'm about to write a script that checks a directory on the server, every 5 minutes, for newly uploaded photos, by my office, and to transfer the photos to another location. I'm using ASP and the FileSystemObject as the application and a Windows Schedule calls it.
What I would like to know is: If the user is sending 150 photos, by FTP, my application is not going to know if the user has finished uploading, or not. So then the application will go through the files one-by-one and transfer them. If my user has a slower connection than the speed of my application, the script may eventually come across the file that is currently being uploaded...
Will my application grab that file thinking it's complete or will it know that it's in the middle of upload and leave it alone? If it DOES grab it and transfers half a photo, how can I stop this from happening?
There is no good way to test for that, much depends on how the uploader is working.
Its highly unlikely that a file currently open for write access while the uploader creates it is going to allow your code to move it. An attempt to move it will result in a sharing violation or similar error. So protecting that section of code with an On Error Resume Next would do it. Have your code skip that file in the knowledge that it will be picked up again when the next poll comes round.

need to copy files on client system, is thr any possible way?

I m developin an Online Examination System in C#.net and want to copy files on client machine as soon as exam starts, so that even if internet gets disconnected examinee can continue with test
You may wish to consider a client server solution, such as WPF or winforms as this is more suited to this type of development. You can use one click deployment to have this still launched from the web and updated on every run.
If you do decied to use asp.net this will result in a very javascript heavy site with a very slow load in the first page.
To do this you would load all your test qustions into a javascript datastructure on the first page, when every the user when to the next page you would need to, using javascript, collect all the answers and store in javascript. then rereender the entire page using your definitions of the test in javascript with no trip back to the server. then once the test was complete you would need to send your results back to the server, the internet must be active once you've compleated the test.
You'll have to create a download package and provide a link for the user to click to request the files. You can't force a download.
If your exam in all in one web page, you don't need to do anything. Once the page appears in the users browser, it has already been "copied locally".

How do you show a preview image when allowing file uploads in ASP.NET?

Here is the functionality I want:
User selects an image from their machine, hits an Upload button (or better yet the following fires on the onchange event of the file input), and is able to see a preview of the image they are about to upload.
Here is the current workflow I am using, but it seems suboptimal:
I have an image control, a file input control and a submit button control. When the submit button is clicked, the codebehind handles the OnClick event and loads the image from the file input element. It then stores it into a temporary folder on the web server and sets the image control's ImageUrl to point to it.
This works, but results in me having to do a lot of janitorial duty in cleaning up these temporary images. Is there a cleaner workflow for doing this?
If you have memory to burn:
cache the image bytes in memory
set your ImageUrl to an image handler (.ashx) with some sort of cache identifier
serve the image bytes from cache
if the user cancels or leaves, discard the cached bytes
if the user accepts, write the cached bytes to their final destination
You should upload and rename the image to match some sort of ID for your current record. Then, when you upload a new file, delete any old ones first, all in the codebehind.
If you are only showing a thumbnail, you should try to use an image library to resize the image before saving. This will save on bandwidth and storage space.
I am assuming that the problem you are trying to solve is for your application to have the ability to preview the image before the user commits to that image. Your current approach has many advantages but one disadvantage is orphaned image files in a temporary directory if the user previews several images before committing or abandons the operation all together.
I've noticed several popular social networking sites using a different approach. Basically, a Java applet is used to do the preview operation on the user's local machine. The only file uploaded to the server is what the user commits to. That approach solves the problem that you are running into; however, it introduces the new problem of requiring Java to be installed on the local machine and integrated with the web browser.
you can create a small executable to delete files on* that temporary folder, and attach it to a schedule task so it will clean your temp. folder once in a while. But I don't know if you're hosting on a dedicated server or shared hosting because with shared hosting, this doesn't work
and is able to see a preview of the image they are about to upload
...
When the submit button is clicked, the codebehind handles the OnClick event and loads the image from the file input element. It then stores it into a temporary folder on the web server and sets the image control's ImageUrl to point to it.
Imagine this conversation:
Jim: I don't know if I can afford to drive my car to work today.
Bob: Why don't you just drive to work? When you pay for it, you'll know if you can afford it or not!
Jim: Awesome!
You've just uploaded the file to show them the preview of the file they're about to upload...
While this will undoubtedly work fine if your users are uploading small images over fast connections, when someone tries to upload a 3 meg JPEG over a slow connection, and then wonders why their webpage locked up from selecting a file (they didn't even press submit remember, so you've effectively locked them up 'randomly'), you may wish to re-evaluate this as a solution.
To actually display the image before it gets uploaded, you will need to use some kind of flash or silverlight object (or perhaps a java applet) which can produce a thumbnail of the local file on the user's local disk, before it gets sent to the server. As ugly as this may sound, there literally is no way to do it without some client side plugin.

Resources