I need to inspect the bits of an uploaded file before it’s ever saved off to the file system. PHP’s documentation has a nice page that tells me exactly what properties are available for me to use (https://www.php.net/manual/en/features.file-upload.post-method.php), but I can’t find something similar for Ruby and/or Rails.
I’ve also tried logging a JSON-formatted string of the upload, but that just gives me a redundant UTF-8 error. I can’t think of anything else to try.
Can anyone offer any insight or point me to the right place?
Thanks.
UPDATE: I’m running Apache 2.2.11 on OS X (Leopard) in case Peter is right (see below).
UPDATE: In case it helps, my input parameter is logged as "upload"=>#<File:/tmp/RackMultipart.64239.1>. I’m just not sure how to access it to get to its "parts".
As far as I’ve been able to tell or find, there is no physical file until an upload is read. This is inline with derfred’s reply. The only metadata that can be accessed is:
Additionally, there’s a
readmethod on theuploaded_filethat allows the file’ content to be accessed and, presumably, written to the permanent file system.Something else that I’ve noticed is that the only means Ruby offers to inspect the MIME type of a file is in this
content_typeproperty of an uploaded file. Once the file is on the file system, there’s no longer any way of accessing or determining the MIME type.