ModPorter - Painless file uploads
Porter is essentially the inverse of X-SendFile. It parses the multipart post in C inside your apache process and writes the files to disk. Once that work is done it changes the request to look like a regular form POST which contains pointers to the temp files on disk.
Related cards:
Carrierwave: How to migrate to another folder structure
A flat folder structure can be cool if you have only a few folders but can be painful for huge amounts. We recently had this issue in a project with more than 100.000 attachments, where we used a structure like this `/attachments/123456789/file.pd...
Dynamically uploading files to Rails with jQuery File Upload
Say we want …
- to create a
Gallery
that has a name andhas_many :images
, which in turn have a caption - to offer the user a single form to create a gallery with any number of images
- immediate uploads with a progress bar per image
- a snapp...
Legacy CarrierWave: How to generate versions with different file extensions
We use CarrierWave in many of our projects to store and serve files of various formats - mostly images. A common use case of CarrierWave's DSL is to "proce...
Common mistakes when storing file uploads with Rails
1. Saving files to a directory that is not shared between deploys or servers
If you save your uploads to a made up directory like "RAILS_ROOT/uploads"
, this directory goes away after every deploy (since every release gets a new). Also this di...
How to: Apache logs on a daily basis without logrotate
If you want to have a new log file every day automatically, but avoid using logrotate
, the CustomLog
directive is your friend:
CustomLog "|/usr/sbin/rotatelogs /opt/www/awesome-project/log/access.%Y-%m-%d.log 86400" combined
Adding that ...
Sanitize user-generated filenames and only send files inside a given directory
If in your application your users pass along params that result in filenames, like invoices/generated?number=123
. This could be your (very careless) controller method:
def generated
send_file File.join(Rails.root, 'shared', 'invoices'...
Check apache config files' syntax
To check your apache2 config files for syntax errors run
sudo apache2ctl configtest
or shorter
sudo apache2ctl -t
Be aware that this does not guarantee a successful Apache startup. It may still fail due to permission errors, etc.
Speed up file downloads with Rails, Apache and X-Sendfile
When you use the send_file
method to send a local file to the browser, you can save resources on the application server by setting the :x_sendfile
option to true
. This option i...
HTML5: Allow to choose multiple files with a vanilla file picker
Modern browsers natively suppport file pickers that allow the user to choose multiple files at once. To activate this feature, set the multiple
attribute:
<input type="file" name="images[]" multiple />
Or in a Rails view:
<%= file_fie...
Apache: SSL with Virtual Hosts Using SNI
With SNI, you can have many virtual hosts with HTTPS sharing the same IP address and port, and each one can have its own unique certificate. SNI is supported by all major browsers except Internet Explorer on XP, Safari on XP, wget, Android and Java.