Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
kevivmatrix committed Dec 24, 2019
2 parents ed7b215 + e39194f commit caf9018
Show file tree
Hide file tree
Showing 33 changed files with 680 additions and 333 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dist: trusty

language: ruby

cache: bundler

rvm:
- 2.5.5
- 2.6.2
- jruby-9.2.6.0
- jruby-9.2.8.0

gemfile:
- gemfiles/rails-5-2.gemfile
Expand Down Expand Up @@ -38,7 +40,7 @@ matrix:
- rvm: jruby-head
gemfile: gemfiles/rails-5-2.gemfile
exclude:
- rvm: jruby-9.2.6.0
- rvm: jruby-9.2.8.0
gemfile: gemfiles/rails-6-0.gemfile
allow_failures:
- rvm: ruby-head
Expand All @@ -52,7 +54,7 @@ notifications:
secure: Npzanyv/LXLIRlrNs8iTUbZNRhXlP+K2ZpjZoS2UKkr09jYyP1qdf5a//R3Lu7Yat7g2b4qTJGbaZBEMUQSVaJ6UX6quiBJjVWxjxjQ4Ugk8k/yOIAcGEGYPfS6YzRXemRwo9j4uy76cmwlv8cwEuYTSTBRK4XrdYHslX6pKSXM=

addons:
postgresql: "9.3"
postgresql: "9.6"
apt:
packages:
- ghostscript
61 changes: 58 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,64 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## 2.0.2 - 2019-09-28

### Fixed
* Fix download causing nil error if the file has empty filename(@fukayatsu [#2419](https://github.com/carrierwaveuploader/carrierwave/pull/2419), [#2411](https://github.com/carrierwaveuploader/carrierwave/issues/2411))

## 2.0.1 - 2019-08-31

### Fixed
* Fix `#{column}_cache` unintentionally removing files on assigning empty string(@mshibuya [22e8005e](https://github.com/carrierwaveuploader/carrierwave/commit/22e8005e44751fbce9f088497853aa60b6c89fcc), [#2412](https://github.com/carrierwaveuploader/carrierwave/issues/2412))

## 2.0.0 - 2019-08-18

_No changes._

## 2.0.0.rc - 2019-06-23
### Added
* Append, reorder, and remove-single-file feature for multiple file uploader(@mshibuya [#2401](https://github.com/carrierwaveuploader/carrierwave/pull/2401))
* Allow retrieval of uploader index within uploaders(@mshibuya [#1771](https://github.com/carrierwaveuploader/carrierwave/issues/1771))
* Add ability to customize downloaders(@mshibuya [#1636](https://github.com/carrierwaveuploader/carrierwave/issues/1636))
* Support internationalized domain names for downloader(@mshibuya [#2086](https://github.com/carrierwaveuploader/carrierwave/issues/2086))
* Support authenticated_url for Aliyun provider(@Nitrino [#2381](https://github.com/carrierwaveuploader/carrierwave/pull/2381))
* Support passing options to authenticated_url for OpenStack provider(@stanhu [#2377](https://github.com/carrierwaveuploader/carrierwave/pull/2377))
* Support authenticated_url for AzureRM provider(@Nitrino [#2375](https://github.com/carrierwaveuploader/carrierwave/pull/2375))
* Allow custom expires_at when building an authenticated_url(@stephankaag [#2397](https://github.com/carrierwaveuploader/carrierwave/pull/2397))

### Changed
* Replace mime-types dependency with mini_mime(@bradleypriest [#2292](https://github.com/carrierwaveuploader/carrierwave/pull/2292))
* Use the MimeMagic gem to inspect file headers for the mime type. This allows for mitigation of CVE-2016-3714, in combination with a `content_type_whitelist`. (@locriani [#1934](https://github.com/carrierwaveuploader/carrierwave/pull/1934))
* Use the storage given by `storage` configuration also for `cache_storage` unless explicitly specified(@mshibuya [629afecb](https://github.com/carrierwaveuploader/carrierwave/commit/629afecbaeccd2300e4660b78ee36bd95dd845c5))
* Improve Fog initialization(@mshibuya [#2395](https://github.com/carrierwaveuploader/carrierwave/issues/2395))
* [BREAKING CHANGE] Multiple file uploader now keeps successful files on update, only discarding failed ones(@mshibuya [7db9195d](https://github.com/carrierwaveuploader/carrierwave/commit/7db9195de3197fcecfb442caa434369fe0e37846))
* [BREAKING CHANGE] `#remote_#{column}_urls=` was changed to preserve precedent updates(@mshibuya [8f18a95b](https://github.com/carrierwaveuploader/carrierwave/commit/8f18a95b74517ba96f6c571401d537f048e36961))
* `#serializable_hash` now returns string for version keys(@schovi [#2246](https://github.com/carrierwaveuploader/carrierwave/pull/2246))
* Use the MimeMagic gem to inspect file headers for the mime type. This allows for mitigation of CVE-2016-3714, in combination with a `content_type_whitelist`(@locriani [#1934](https://github.com/carrierwaveuploader/carrierwave/pull/1934))
* Replace mime-types dependency with mini_mime to save memory(@bradleypriest [#2292](https://github.com/carrierwaveuploader/carrierwave/pull/2292))
* Delegate MiniMagick processing to ImageProcessing gem(@janko [#2298](https://github.com/carrierwaveuploader/carrierwave/pull/2298))
* Handle ActiveRecord transaction correctly, not storing or removing files on rollback(@skosh [#2209](https://github.com/carrierwaveuploader/carrierwave/pull/2209))

### Deprecated
* `fog_provider` configuration was deprecated and has no effect, just adding fog providers to `Gemfile` will load them(@mshibuya [ca201ee2](https://github.com/carrierwaveuploader/carrierwave/commit/ca201ee2ceebe2d916be3bc1396fe381cc93afd7))
* `CarrierWave::Uploader::Base#sanitized_file` was deprecated, use `#file` instead(@mshibuya [28190e99](https://github.com/carrierwaveuploader/carrierwave/commit/28190e99299a6131c0424a5d10205f471e39f3cd))

### Removed
* Remove support for Rails 4.x and Ruby 2.0/2.1 (@mshibuya [bada043f](https://github.com/carrierwaveuploader/carrierwave/commit/bada043f39801625d748b9a89ef475eff5c8bdd5))

### Fixed
* Fix deleting files twice when marked for removal(@mshibuya [67800fde](https://github.com/carrierwaveuploader/carrierwave/commit/67800fdeb796a7b2efe1192e06f619dcc3c64f05))
* Fix `uploader.cache!` loads entire contents of file into memory(@mshibuya [#2136](https://github.com/carrierwaveuploader/carrierwave/issues/2136))
* Do not trigger *_will_change! when file is not to be removed(@mshibuya [#2323](https://github.com/carrierwaveuploader/carrierwave/issues/2323))
* Allow deleting all files for multiple file upload(@mshibuya [#1990](https://github.com/carrierwaveuploader/carrierwave/issues/1990))
* Failing to retrieve unquoted filenames from Content-Disposition(@mshibuya [#2364](https://github.com/carrierwaveuploader/carrierwave/issues/2364))
* Fix `#clean_cache!` breaking with old format of cache id(@mshibuya [aab402fb](https://github.com/carrierwaveuploader/carrierwave/commit/aab402fb5232c0ebfe2584c22c3fb0161613dc33))
* Fix `#exists?` returning true after Fog file deletion(@mshibuya [#2387](https://github.com/carrierwaveuploader/carrierwave/issues/2387))
* Make `#identifier` available for a retrieved file(@mshibuya [#1581](https://github.com/carrierwaveuploader/carrierwave/issues/1581))
* Make cache id generation less predictable(@mshibuya [#2326](https://github.com/carrierwaveuploader/carrierwave/issues/2326))
* Uploaders not being cleared when `#reload` or `#initialize_dup` are overridden in model(@mshibuya [#2379](https://github.com/carrierwaveuploader/carrierwave/issues/2379))
* Fix `#content_type` returning false, instead of nil(@longkt90 [#2384](https://github.com/carrierwaveuploader/carrierwave/pull/2384))
* Preserve connection cache when eagar-loading fog(@dmitryshagin [#2383](https://github.com/carrierwaveuploader/carrierwave/pull/2383))
* `#recreate_versions!` ignored `:from_version` when versions to recreate are given(@hedgesky [#1879](https://github.com/carrierwaveuploader/carrierwave/pull/1879) [#1164](https://github.com/carrierwaveuploader/carrierwave/issues/1164))

## 1.3.1 - 2018-12-29
### Fixed
Expand Down Expand Up @@ -137,7 +192,7 @@ _No changes._
* Don't read file twice when calling `sanitized_file` or `cache!` (@felixbuenemann [#1476](https://github.com/carrierwaveuploader/carrierwave/pull/1476))
* Change image extension when converting formats (@nashby [#1446](https://github.com/carrierwaveuploader/carrierwave/pull/1446))
* Fix file delete being called twice on remove (@adamcrown [#1441](https://github.com/carrierwaveuploader/carrierwave/pull/1441))
* RSpec 3 support (@randoum #1421[](https://github.com/carrierwaveuploader/carrierwave/pull/1421), @akiomik [#1370](https://github.com/carrierwaveuploader/carrierwave/pull/1370))
* RSpec 3 support (@randoum [#1421](https://github.com/carrierwaveuploader/carrierwave/pull/1421), @akiomik [#1370](https://github.com/carrierwaveuploader/carrierwave/pull/1370))
* MiniMagick convert to a format all the pages by default and accept an optional page number parameter to convert specific pages (@harikrishnan83 [#1408](https://github.com/carrierwaveuploader/carrierwave/pull/1408))
* Fix cache workfile collision between versions (@jvdp [#1399](https://github.com/carrierwaveuploader/carrierwave/pull/1399))
* Reset mounter cache on record reload (@semenyukdmitriy [#1383](https://github.com/carrierwaveuploader/carrierwave/pull/1383))
Expand Down
42 changes: 29 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ $ gem install carrierwave
In Rails, add it to your Gemfile:

```ruby
gem 'carrierwave', '~> 1.0'
gem 'carrierwave', '~> 2.0'
```

Finally, restart the server to apply the changes.

As of version 1.0, CarrierWave requires Rails 4.0 or higher and Ruby 2.0
or higher. If you're on Rails 3, you should use v0.11.0.
As of version 2.0, CarrierWave requires Rails 5.0 or higher and Ruby 2.2
or higher. If you're on Rails 4, you should use 1.x.

## Getting Started

Expand Down Expand Up @@ -190,6 +190,17 @@ u.avatars[0].current_path # => 'path/to/file.png'
u.avatars[0].identifier # => 'file.png'
```

If you want to preserve existing files on uploading new one, you can go like:

```erb
<% user.avatars.each do |avatar| %>
<%= hidden_field :user, :avatars, multiple: true, value: avatar.identifier %>
<% end %>
<%= form.file_field :avatars, multiple: true %>
```

Sorting avatars is supported as well by reordering `hidden_field`, an example using jQuery UI Sortable is available [here](https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Add%2C-remove-and-reorder-images-using-multiple-file-upload).

## Changing the storage directory

In order to change where uploaded files are put, just override the `store_dir`
Expand Down Expand Up @@ -321,15 +332,13 @@ end

When this uploader is used, an uploaded image would be scaled to be no larger
than 800 by 800 pixels. The original aspect ratio will be kept.
A version called thumb is then created, which is scaled
to exactly 200 by 200 pixels.

If you would like to crop images to a specific height and width you
can use the alternative option of '''resize_to_fill'''. It will make sure
A version called `:thumb` is then created, which is scaled
to exactly 200 by 200 pixels. The thumbnail uses `resize_to_fill` which makes sure
that the width and height specified are filled, only cropping
if the aspect ratio requires it.

The uploader could be used like this:
The above uploader could be used like this:

```ruby
uploader = AvatarUploader.new
Expand All @@ -342,6 +351,18 @@ uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
One important thing to remember is that process is called *before* versions are
created. This can cut down on processing cost.

### Processing Methods: mini_magick

- `convert` - Changes the image encoding format to the given format, eg. jpg
- `resize_to_limit` - Resize the image to fit within the specified dimensions while retaining the original aspect ratio. Will only resize the image if it is larger than the specified dimensions. The resulting image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
- `resize_to_fit` - Resize the image to fit within the specified dimensions while retaining the original aspect ratio. The image may be shorter or narrower than specified in the smaller dimension but will not be larger than the specified values.
- `resize_to_fill` - Resize the image to fit within the specified dimensions while retaining the aspect ratio of the original image. If necessary, crop the image in the larger dimension. Optionally, a "gravity" may be specified, for example "Center", or "NorthEast".
- `resize_and_pad` - Resize the image to fit within the specified dimensions while retaining the original aspect ratio. If necessary, will pad the remaining area with the given color, which defaults to transparent (for gif and png, white for jpeg). Optionally, a "gravity" may be specified, as above.

See `carrierwave/processing/mini_magick.rb` for details.

### Nested versions

It is possible to nest versions within versions:

```ruby
Expand Down Expand Up @@ -667,7 +688,6 @@ If you want to use fog you must add in your CarrierWave initializer the
following lines

```ruby
config.fog_provider = 'fog' # 'fog/aws' etc. Defaults to 'fog'
config.fog_credentials = { ... } # Provider specific credentials
```

Expand All @@ -685,7 +705,6 @@ You can also pass in additional options, as documented fully in lib/carrierwave/

```ruby
CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'xxx', # required unless using use_iam_profile
Expand Down Expand Up @@ -734,7 +753,6 @@ Using a US-based account:

```ruby
CarrierWave.configure do |config|
config.fog_provider = "fog/rackspace/storage" # optional, defaults to "fog"
config.fog_credentials = {
provider: 'Rackspace',
rackspace_username: 'xxxxxx',
Expand All @@ -749,7 +767,6 @@ Using a UK-based account:

```ruby
CarrierWave.configure do |config|
config.fog_provider = "fog/rackspace/storage" # optional, defaults to "fog"
config.fog_credentials = {
provider: 'Rackspace',
rackspace_username: 'xxxxxx',
Expand Down Expand Up @@ -798,7 +815,6 @@ Please read the [fog-google README](https://github.com/fog/fog-google/blob/maste

```ruby
CarrierWave.configure do |config|
config.fog_provider = 'fog/google' # required
config.fog_credentials = {
provider: 'Google',
google_storage_access_key_id: 'xxxxxx',
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-6-0.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"

gem "rails", "~> 6.0.0.beta3"
gem "rails", "~> 6.0.0"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby

Expand Down
4 changes: 4 additions & 0 deletions lib/carrierwave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class Railtie < Rails::Railtie
require 'carrierwave/orm/activerecord'
end
end

config.before_eager_load do
CarrierWave::Storage::Fog.eager_load
end
end
end

Expand Down
10 changes: 6 additions & 4 deletions lib/carrierwave/downloader/remote_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ def respond_to?(*args)
private

def filename_from_header
if file.meta.include? 'content-disposition'
match = file.meta['content-disposition'].match(/filename=(?:"([^"]+)"|([^";]+))/)
match[1].presence || match[2].presence
end
return nil unless file.meta.include? 'content-disposition'

match = file.meta['content-disposition'].match(/filename=(?:"([^"]+)"|([^";]+))/)
return nil unless match

match[1].presence || match[2].presence
end

def filename_from_uri
Expand Down
44 changes: 25 additions & 19 deletions lib/carrierwave/mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,26 @@ def write_#{column}_identifier
return if frozen?
mounter = _mounter(:#{column})
if mounter.remove?
write_uploader(mounter.serialization_column, nil)
elsif mounter.identifiers.first
write_uploader(mounter.serialization_column, mounter.identifiers.first)
end
mounter.clear! if mounter.remove?
write_uploader(mounter.serialization_column, mounter.identifiers.first)
end
def #{column}_identifier
_mounter(:#{column}).read_identifiers[0]
end
def #{column}_integrity_error
#{column}_integrity_errors.last
end
def #{column}_processing_error
#{column}_processing_errors.last
end
def #{column}_download_error
#{column}_download_errors.last
end
def store_previous_changes_for_#{column}
attribute_changes = ::ActiveRecord.version.to_s.to_f >= 5.1 ? saved_changes : changes
@_previous_changes_for_#{column} = attribute_changes[_mounter(:#{column}).serialization_column]
Expand Down Expand Up @@ -240,9 +249,9 @@ def remove_previously_stored_#{column}
# [store_images!] Stores all files that have been assigned with +images=+
# [remove_images!] Removes the uploaded file from the filesystem.
#
# [images_integrity_error] Returns an error object if the last files to be assigned caused an integrity error
# [images_processing_error] Returns an error object if the last files to be assigned caused a processing error
# [images_download_error] Returns an error object if the last files to be remotely assigned caused a download error
# [image_integrity_errors] Returns error objects of files which failed to pass integrity check
# [image_processing_errors] Returns error objects of files which failed to be processed
# [image_download_errors] Returns error objects of files which failed to be downloaded
#
# [image_identifiers] Reads out the identifiers of the files
#
Expand Down Expand Up @@ -329,11 +338,8 @@ def write_#{column}_identifier
return if frozen?
mounter = _mounter(:#{column})
if mounter.remove?
write_uploader(mounter.serialization_column, nil)
elsif mounter.identifiers.any?
write_uploader(mounter.serialization_column, mounter.identifiers)
end
mounter.clear! if mounter.remove?
write_uploader(mounter.serialization_column, mounter.identifiers.presence)
end
def #{column}_identifiers
Expand Down Expand Up @@ -395,16 +401,16 @@ def store_#{column}!
_mounter(:#{column}).store!
end
def #{column}_integrity_error
_mounter(:#{column}).integrity_error
def #{column}_integrity_errors
_mounter(:#{column}).integrity_errors
end
def #{column}_processing_error
_mounter(:#{column}).processing_error
def #{column}_processing_errors
_mounter(:#{column}).processing_errors
end
def #{column}_download_error
_mounter(:#{column}).download_error
def #{column}_download_errors
_mounter(:#{column}).download_errors
end
def mark_remove_#{column}_false
Expand Down
Loading

0 comments on commit caf9018

Please sign in to comment.