Can I preserve files input at Meteor hot code push? - meteor

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 :-)

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

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.

Is there any way to "peek" at a file while it's uploading through HTTP onto a Windows box?

I need to add a file upload function to an ASP.NET website and would like to be able to read a small portion of the file on the server while it's still uploading. A peek or preview type function so I can determine contents and give some feedback to the user while it is still uploading (we're talking about large files here). Is there any way to do this? I'm thinking worst case of writing a custom control which uploads only a fixed number of bytes of the file once chosen and then under the covers starts another upload of the full file. Not totally sure even this is possible, but I'm looking for a more elegant solution anyway... Thanks!
It sounds like you want to avoid the "white screen of death" during large file uploads. If so, you might want to look into Telerik's RadUpload control , which provides a progress bar during upload.
If you want to roll your own, I'd decompile their trial copy for ideas. I've peeked at their source in this way, and they accomplish the progress bar through a combination of a custom HttpModule and HttpHandler along with their control. The handler routes the file in a streamed fashion while the module provides "percent complete" information--or the other way round; it's been a few years since I looked at it.
Edit:
Actually, I'm trying to do server-side processing as the file is still being uploaded. I want to import user data via HTTP, but want to present the user with preview/options of how we'll process their data while the file is still uploading (column definitions, etc.). No matter what, we'll take the file as is, so the upload doesn't need to be interrupted. Given that I actually want interaction during the upload based on reading a relatively small portion of the file as it is being uploaded, would you still recommend the same approach?
Well... it'd be very difficult to do, and it might not work cross-browser, but it could be done with this approach.
Since it's entirely possible to work with the incoming file as a stream as I mentioned, you could have your intial processing update some state as part of that stream processing. If you don't process as a stream, you have to wait for the full file upload before you can do anything with it.
The problem is this: during the file upload, you cannot have any more HTML-based interaction. The post must continue unabated or the upload will fail. The control I linked only works at all because most browsers allow javascript to continue to execute and update page DOM during the post.
So in order to make this work, you have to update some standardized state server-side during your file processing in the HttpModule, which is transmitted back to the client via XmlHttpRequest calls handled by the HttpHandler. You have to use pure javascript/DOM to update the UI for the user.
So, as I said, it's complex and likely to be buggy cross-browser, but it could theoretically be done.
There are alernatives that might be more stable, but might not necessarily be feasible: you could build an ActiveX control or a Click-Once .NET application that pre-processes the file before upload, and maybe even asynchronously transfers the file while the user continues browsing. Some users may not like that option, and I don't know the particulars of your deployment scenario, but it's an option.
There is an HTTP HEAD method but not PEEK.
HEAD will give you information and headers about the file.
Of course you can make a special request handler that does anything you want. You don't have to work with static resources, you can dynamically create any response you want.

Background File Copy process in ASP

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.

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