How to get the download status of file in ASP.NET mvc2 - asp.net-mvc

In my mvc2 project i have a method called DownloadPDF. In that i have,
httpContext.Response.WriteFile(<FilePath>);
httpContext.ApplicationInstance.CompleteRequest();
I wan't to track whether the file has downloaded successfully. I referred following tutorial but it doesn't work when i host the project in IIS.
http://www.codeproject.com/Articles/74654/File-Download-in-ASP-NET-and-Tracking-the-Status-o

If you application targeted for HTML 5 browser means, try the "Html5 Progress Event". It will supply all the necessary information
total - Total bytes being transferred
loaded - Bytes uploaded thus far
lengthComputable - Specifies if the total size of the data/file
being uploaded is known
For more information:
http://www.matlus.com/html5-file-upload-with-progress/

Related

In Unity3D for iOS when loading on demand resources, how can I check the latest version is already loaded and if not, what is the download size?

I've recently transitioned my iOS Unity app to use asset bundles as on demand resources. This all works great! The only problem is that when the application first starts up and all the ODRs are preloaded it just starts to download them from the apple servers. I need to know before preloading them if they require downloading and if so, how big of a download. I need this info to show a prompt for the user to let them know that additional data needs to be downloaded and maybe turn on their wifi etc.
If you are using WWW class then there is this WWW.LoadFromCacheOrDownload, this function takes in a version parameter which you can probably use for checking on versions.
If you are using UnityWebRequest, then maybe you can use the meta files which get generated with asset bundle and then download it and read version or a hash (You will probably have to google a little bit on this what to use) to actually look if you have a version change and do you need to download new version or not.
If none of the above suits you then the hard coded way would be to setup a list of your asset bundles with your versions on a webserver and download it to match it with your local version everytime you start the app.
I hope this atleast helps you look in the correct direction.
I've managed to do this myself in the end. My current setup is the following:
I have a bunch of assetbundles marked as On Demand Resources.
When I build the assetbundles I save a file containing the CRC and file sizes of all these bundles and I save it in StreamingAssets to always have it available
Whenever the app starts up, I try to load the assetbundles from PersistentDataPath against their latest CRC (at first launch there will be no bundles there)
If any bundles are missing or have invalid CRC, show a prompt to the user that x MB of data needs to be downloaded (taken from the file made at build time)
After the ODR resources are downloaded, I reencrypt the assetbundle from res:// (the only way I could access it) and move it to PersistentDataPath
Whenever a new updated comes it, it should contain new CRCs for the changed bundles and the process should restart
It seems to work quite well. The only real issues that I have is that I currently don't know how to delete the downloaded ODR data, and there could be a version mismatch if a user installs the app and defers downloading the extra data, and only opts to do so when an updated version of the app (with different bundle CRCs) is available on the server but they still stay on the older version. This would probabily load the new bundles but will fail the CRC checks for them...

Restoring/creating missing media references in Umbraco Media section

I have an Umbraco (v6.1.6) website, hosted on Azure Hosted (Website & DB).
Recently the client reported, that some images have disappeared from the website!
Looking at the CMS back office, the content nodes are referencing media items, but 'some' of those items are no longer present in the media section! The media files are however present on the web server in the /media folder as expected!
Now, this should be running as a single instance site, but looks like the site was run in with multiple(3) instances for a while, such as when the missing images were loaded.
[All the unaffected media has lower id’s (<10000) while the missing items in the media section have higher ids (20000’s or 50000’s)]
The site is now back to running one instance.
Q. Is there a way I can re-generate the items in the Umbraco Media section, based on the media actually present in the /Media folder?
What you need to do depends a lot on the state of your site and what has been going on while it was running in 3 instances... and what you want the outcome to be!
Metadata for media in umbraco is stored in the database and the actual files are stored on disk. If your site has been running in 3 instances using the same database but different file locations on disk, you should actually be seeing that the media items exist in the database even though the files might be scattered in the 3 instances on the file system.
It however sounds like you're saying that the files all do exist on disk, but the media items not all exist in the database. Can you confirm this (as it sounds really strange unless you have been running 3 different databases also).
All in all, everything here sounds really strange since running 3 instances should also require you to have had this running and accessed by the editors uploading the files, using 3 different hostnames?
No matter what I don't think theres a simple solution to your problem. There's no way to have umbraco "reindex" the media folder based on the files there. What I have done for broken media libraries (usually self inflicted breakage, that is) is to load up all existing media items in memory and then loop through the file system to see what is missing from the library and recreate those media items and upload the files to them. Do remember to log which files you are recreating as media items so you can do a file system delete of the orphaned files after they have been processed.
If you can shed a bit more light on the issue, I will see if I can come up with a better solution for you.

Download files with AFNetworking, check for updates (Etag, last modified)

I've been searching around documentations and also the web, but I am still unsure how to do this right:
I have a large number of files that I want to download and store locally to display them in my app (PDFs, images in various resolutions, ...)
I have a number of requirements:
The files need to be available in offline conditions.
The files need to be up to date (check for new versions of the file regularly like twice a day)
I need access to the local file URL, not only a NSData memory representation of the file
the local files should never be deleted automatically, only through user interaction.
I am supporting iOS 6.1+.
I am using AFNetworking (currently 1.1)
I have control of the hosting server, so I can set appropriate http headers.
This is what the process should be like:
Example: UI requires resource
check if resource is available at local path, if yes load resource from local path
check server for new version, HEAD request
compare Etag or modified date with local version
download file if it has been updated
replace local file
notify the UI that a new version can be loaded from the local path
Now my question is, how should I implement this given the requirements?
Specifically, which parts of this can be done by NSURLConnection / AFNetworking, which parts do I have to implement myself?

Installing applications OTA

I have a system set up to download jad files on users' Blackberries, but it only works intermittently, and seemingly randomly. If the user clicks on the link within their BlackBerry browser, 95% of the time on the first try an error message will pop up saying there was an HTTP 500 error (which our server never returns).
Viewing the details of this message within the blackberry browser, it says nothing but java.lang.nullpointerexception which, again, could not have come from our server (running apache/php).
However, if the user clicks on the link a few more times, or navigates away and goes back to that page, it suddenly works. No change on the server, it just shows the application install screen. Unfortunately, this doesn't always work; sometimes the error 500 just keeps showing up.
The link is rather long (containing an sha hash as a token as part of the URL), but I would think that a long URL would either always be broken or always work, not work intermittently.
The link uses a php script to download the jad and cod files. Linking to the files directly rather than using the script seems to work more often (I haven't determined if that also ever has an error 500 or not), but I can't find any issues with the headers. The content type is set correctly and, like I said, if the headers were an issue, I'd think it would either always work or always break.
Any clues?
You may be able to shed some light on the problem by looking at the event logs, which you can get using JavaLoader:
javaloader -u eventlog > event.log
Search for NullPointerException within those logs and you'll be able to see what's causing it.
I can't explain the intermittent behaviour, but I had a similar situation where I was getting the java.lang.NullPointerException in the browser details. Unfortunately, the Event Log (as dumped by javaloader.exe) or by viewing on-device using Alt-L-G-L-G didn't show the exception.
(I'm using bb-ant-tools and JDE 4.6.1.) When the signature tool ran, I noticed that there were two .cod files being signed and I can see both of them inside the .jar file the compiler creates. But the output written was a single .cod file of size 92306 bytes that was not a .zip of smaller .cod files. The compiler somehow was not able to create a .cod that contained siblings. For comparison, compiling the project with JDE 5.0.0 created sibling .cod files that were able to be loaded over OTA.
My project included an .mp3 file of 53542 bytes which I happened to not require. After removing it, the 4.6.1 compiler outputted a single .cod and I was able to successfully download it via OTA.

Continue an interrupted download on iPhone

I use NSURLConnection to download large files from the web on iPhone. I use the "didReceiveData" method to append data to a file in the Documents folder. It works fine.
If the download is interrupted (for instance, because the user pressed the "home" button), I would like to be able to continue to download the next time the user launch my application, and not from scratch!
Anyone can help me ?
ASIHTTPRequest has easy to use support for resuming downloads:
http://allseeing-i.com/ASIHTTPRequest/How-to-use#resume
Alternatively, find out how much data you have downloaded already by looking at the size of the existing data, and set the 'Range' header on your NSMutableURLRequest:
[request addValue:#"bytes=x-" forHTTPHeaderField:#"Range"];
..where x is the size in bytes of the data you have already. This will download data starting from byte x. You can then append this data to your file as you receive it.
Note that the web server you are downloading from must support partial downloads for the resource you are trying to download - it sends the Accept-Ranges header if so. You can't generally resume downloads for dynamically generated content (e.g. a page generated by a script on the server).
The only method I can think of is to break the file you're downloading up into smaller files. You can use the
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
method to determine when each portion of the file is finished, and restart the download at the last portion that didn't get downloaded.
Look at the HTTP standard to see how you would form a request to start a transfer of a resource from a specific offset. I can't find any code offhand, sorry.

Resources