aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/upload.rb
Commit message (Collapse)AuthorAgeFilesLines
* Restore UploadedFile compatibility with IO.copy_streamJanko Marohnić2019-02-231-1/+4
| | | | | | | | | | | | | | | | | | In https://github.com/rails/rails/pull/28676 the `#to_path` method was added to `ActionDispatch::Http::UploadedFile`. This broke usage with `IO.copy_stream`: source = ActionDispatch::Http::UploadedFile.new(...) IO.copy_stream(source, destination) # ~> TypeError: can't convert ActionDispatch::Http::UploadedFile to IO (ActionDispatch::Http::UploadedFile#to_io gives Tempfile) Normally `IO.copy_stream` just calls `#read` on the source object. However, when `#to_path` is defined, `IO.copy_stream` calls `#to_io` in order to retrieve the raw `File` object. In that case it trips up, because `ActionDispatch::Http::UploadedFile#to_io` returned a `Tempfile` object, which is not an `IO` subclass. We fix this by having `#to_io` return an actual `File` object.
* Add implicit to path conversion to uploaded file (#28676)Aaron Kromer2018-07-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add implicit to path conversion to uploaded file Ruby has a few implicit conversion protocols (e.g. `to_hash`, `to_str`, `to_path`, etc.). These are considered implicit conversion protocols because in certain instances Ruby (MRI core objects) will check if an argument responds to the appropriate protocol and automatically convert it when it does; this is why you can provide a `Pathname` instance into `File.read` without having to explicitly call `to_s`. ```ruby a_file_path = 'some/path/file.ext' File.write a_file_path, 'String Path Content' File.read a_file_path a_pathname = Pathname(a_file_path) File.write core_file, 'Pathname Content' File.read a_file_path core_file = File.new(a_pathname) File.write core_file, 'File Content' File.read core_file tmp_file = Tempfile.new('example') File.write tmp_file, 'Tempfile Content' File.read tmp_file ``` So how does an uploaded file work in such cases? ```ruby tmp_file = Tempfile.new('example') File.write tmp_file, 'Uploaded Content' uploaded_file = ActionDispatch::Http::UploadedFile.new(tempfile: tmp_file) File.read uploaded_file ``` It fails with a `TypeError`: no implicit conversion of ActionDispatch::Http::UploadedFile into String In order to make an uploaded file work it must be explicitly converted to a file path using `path`. ```ruby File.read uploaded_file.path ``` This requires any code that expects path/file like objects to either special case an uploaded file, re-implement the path conversion protocol to use `path`, or forces the developer to explicitly cast uploaded files to paths. This last option can sometimes be difficult to do when such calls are deep within the inner workings of libraries. Since an uploaded file already has a path it makes sense to implement the implicit "path" conversion protocol (just like `File` and `Tempfile`). This change allows uploaded file content to be treated more closely to regular file content, without requiring any special case handling or explicit conversion for common file utilities. * Note uploaded file path delegation in CHANGELOG
* Use frozen string literal in actionpack/Kir Shatrov2017-07-291-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fixed string being modified in place causing frozen string errors in Ruby 2.3sepehr5002017-05-151-2/+6
|
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-3/+3
|
* applies new string literal convention in actionpack/libXavier Noria2016-08-061-1/+1
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Assume uploaded filename is UTF-8Kohei Suzuki2015-08-051-1/+7
|
* always transcode the file to utf-8Aaron Patterson2014-07-161-0/+1
| | | | | | people may be passing filenames to the constructor that are not utf-8, but they will assome that calling `original_filename` returns utf-8 (because that's what it used to do).
* rack 1.6 encodes the filenames in posts correctly nowAaron Patterson2014-07-151-8/+1
|
* Implement to_io as an aliasRafael Mendonça França2014-04-171-5/+1
|
* Provide interface for accessing underlying IO objectTim Linquist2014-04-151-0/+5
| | | | | | In some cases users may need to work with/manipulate more of the Tempfile api than provided by Upload. Allow users to get at the underlying io via the common to_io method of IO/IO-like objects
* Normalize file parameters in same place as other parameters ↵robertomiranda2013-08-141-13/+0
| | | | (ActionDispatch::Http::Parameters#normalize_encode_params)
* Merge branch 'master' of github.com:lifo/docrailsVijay Dev2013-03-301-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/adapter_test.rb guides/source/testing.md [ci skip]
| * Fixed small typosPrathamesh Sonpatki2013-03-191-1/+1
| |
* | UTF-8 encode all keys and values in nested params hash.Teo Hui Ming2013-03-151-4/+4
|/
* Use Encoding::UTF_8 constant :do_not_litter:Akira Matsuda2013-01-281-1/+1
|
* Namespace HashWithIndifferentAccessAkira Matsuda2013-01-071-1/+1
|
* Add documentation to ActionDispatch::Http::UploadedFile#headersRafael Mendonça França2013-01-031-0/+1
| | | | [ci skip]
* Remove a useless TODO commentRobin Dupret2013-01-031-1/+0
|
* documents ActionDispatch::Http::UploadedFileXavier Noria2012-09-221-6/+55
|
* Accept parameters in methods delegated to tempfileSergio Gil Pérez de la Manga2012-09-221-6/+2
|
* Delegate ActionDispatch::Http::UploadedFile#close to tempfileSergio Gil Pérez de la Manga2012-09-201-1/+1
|
* adds delegetion for eof? to AD::Http::UploadedFileJens Fahnenbruck2012-03-271-1/+1
| | | | | if you want to read the file you may need to ask if there is something to read from
* Refactor AD::UploadedFile, and raise sooner if tempfile is not presentCarlos Antonio da Silva2012-03-061-8/+6
|
* deprecate String#encoding_aware? and remove its usageSergey Nartimov2011-12-241-2/+2
|
* Refactor ActionDispatch::Http::UploadedFileDaniel Schierbeck2011-08-281-14/+3
|
* all requests are utf-8. Don't use the external encoding.Damien Mathieu2011-06-141-3/+2
|
* encode the uploaded file's name in the default external encoding - Closes #869Damien Mathieu2011-06-141-1/+12
|
* delegating path and open to internal tempfileAaron Patterson2010-11-181-2/+8
|
* only forwarding enough methods to work. People should grab the delegate ↵Aaron Patterson2010-10-041-5/+8
| | | | tempfile if they really need to do hard work
* making sure respond_to? works properlyAaron Patterson2010-10-041-0/+5
|
* raising an argument error if tempfile is not providedAaron Patterson2010-10-041-0/+1
|
* delegate to the @tempfile instance variableAaron Patterson2010-10-041-13/+5
|
* Improve performance of applications using file uploads by not busting the ↵Carl Lerche2010-09-221-29/+20
| | | | method cache on every request containing a file upload.
* Fix a bunch of minor spelling mistakesEvgeniy Dolzhenko2010-06-111-2/+2
|
* adds missing requires for Object#blank? and Object#present?Xavier Noria2010-03-281-0/+2
|
* Split ActionDispatch http in smaller chunks.José Valim2010-01-161-0/+48