質問編集履歴

4

修正

2023/01/15 12:10

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -12,16 +12,18 @@
12
12
 
13
13
  画像に関するコード
14
14
  ```
15
- class PhotoContentUploader < CarrierWave::Uploader::Base
15
+ class PhotoUploader < CarrierWave::Uploader::Base
16
16
  # Include RMagick or MiniMagick support:
17
17
  # include CarrierWave::RMagick
18
- # include CarrierWave::MiniMagick
18
+ include CarrierWave::MiniMagick
19
-
19
+ process resize_and_pad: [1000, 650, "#ffffff", "Center"]
20
+
21
+
20
22
  # Choose what kind of storage to use for this uploader:
21
- if Rails.env.production?
23
+ if Rails.env.development?
24
+ storage :file
25
+ else
22
26
  include Cloudinary::CarrierWave
23
- else
24
- storage :file
25
27
  end
26
28
 
27
29
  def extension_white_list
@@ -59,9 +61,9 @@
59
61
  # process resize_to_fit: [50, 50]
60
62
  # end
61
63
 
62
- # Add a white list of extensions which are allowed to be uploaded.
64
+ # Add an allowlist of extensions which are allowed to be uploaded.
63
65
  # For images you might use something like this:
64
- # def extension_whitelist
66
+ # def extension_allowlist
65
67
  # %w(jpg jpeg gif png)
66
68
  # end
67
69
 
@@ -71,4 +73,5 @@
71
73
  # "something.jpg" if original_filename
72
74
  # end
73
75
  end
76
+
74
77
  ```

3

追記

2023/01/15 12:09

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -10,7 +10,7 @@
10
10
  デコードのエラーに関する質問
11
11
  https://teratail.com/questions/rn48se0qm091p3
12
12
 
13
-
13
+ 画像に関するコード
14
14
  ```
15
15
  class PhotoContentUploader < CarrierWave::Uploader::Base
16
16
  # Include RMagick or MiniMagick support:

2

追記

2023/01/15 12:08

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,66 @@
9
9
 
10
10
  デコードのエラーに関する質問
11
11
  https://teratail.com/questions/rn48se0qm091p3
12
+
13
+
14
+ ```
15
+ class PhotoContentUploader < CarrierWave::Uploader::Base
16
+ # Include RMagick or MiniMagick support:
17
+ # include CarrierWave::RMagick
18
+ # include CarrierWave::MiniMagick
19
+
20
+ # Choose what kind of storage to use for this uploader:
21
+ if Rails.env.production?
22
+ include Cloudinary::CarrierWave
23
+ else
24
+ storage :file
25
+ end
26
+
27
+ def extension_white_list
28
+ %w(jpg jpeg gif png)
29
+ end
30
+
31
+ def size_range
32
+ 1..5.megabytes
33
+ end
34
+ # storage :fog
35
+
36
+ # Override the directory where uploaded files will be stored.
37
+ # This is a sensible default for uploaders that are meant to be mounted:
38
+ def store_dir
39
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
40
+ end
41
+
42
+ # Provide a default URL as a default if there hasn't been a file uploaded:
43
+ # def default_url(*args)
44
+ # # For Rails 3.1+ asset pipeline compatibility:
45
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
46
+ #
47
+ # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
48
+ # end
49
+
50
+ # Process files as they are uploaded:
51
+ # process scale: [200, 300]
52
+ #
53
+ # def scale(width, height)
54
+ # # do something
55
+ # end
56
+
57
+ # Create different versions of your uploaded files:
58
+ # version :thumb do
59
+ # process resize_to_fit: [50, 50]
60
+ # end
61
+
62
+ # Add a white list of extensions which are allowed to be uploaded.
63
+ # For images you might use something like this:
64
+ # def extension_whitelist
65
+ # %w(jpg jpeg gif png)
66
+ # end
67
+
68
+ # Override the filename of the uploaded files:
69
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
70
+ # def filename
71
+ # "something.jpg" if original_filename
72
+ # end
73
+ end
74
+ ```

1

修正

2023/01/11 09:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,6 @@
2
2
  herokuにデプロイしたアプリが画像をデコードできないということでエラーが発生しました。
3
3
  開発環境では画像がデコードされており、本番環境に限った問題っぽいです。
4
4
  別でそのエラーに関する質問をしていたのですが、
5
- 別でデコードエラーに関する疑問を知りたいです。
6
5
 
7
6
  デコードできないのは、文字列が認識されていないからでしょうか?
8
7
  画像(image)の型はstringです。