How to access and download a file from a server using HTML 5

HTML5 supports the download attribute: http://webreflection.blogspot.com/2011/08/html5-how-to-create-downloads-on-fly.html Example: Clicking on this will allow the browser to handle the download (instead of opening the file using whatever application is associated with the mimetype), including a progress bar. Note: You really want to be careful not to deviate from normal user expectation by trying to create your own … Read more

Uploading a file in Rails

Update 2018 While everything written below still holds true, Rails 5.2 now includes active_storage, which allows stuff like uploading directly to S3 (or other cloud storage services), image transformations, etc. You should check out the rails guide and decide for yourself what fits your needs. While there are plenty of gems that solve file uploading pretty nicely (see https://www.ruby-toolbox.com/categories/rails_file_uploads for … Read more

Python IOError: File not open for reading

You opened the file for writing by specifying the mode as ‘w’; open the file for reading instead: ‘r’ is the default, so it can be omitted. If you need to both read and write, use the + mode: w+ opens the file for writing (truncates it to 0 bytes) but also lets you read from it. If you use r+ it … Read more

File to byte[] in Java

It depends on what best means for you. Productivity wise, don’t reinvent the wheel and use Apache Commons. Which is here FileUtils.readFileToByteArray(File input).