The contents of the data saved by CarrierWave.

Survey background </ font>

I uploaded the image data by CarrierWave, but when I wanted to update the data, I investigated how the data was stored. (Some people may have read this article, and some may have referred to it.)

In the database, only the file name is displayed as shown below (image column) image.png

DB UI uses "sequel pro". If you look at the column value details, it's just the filename. image.png

environment </ font>

item Contents
OS.Catalina v10.15.4
Ruby v2.5.1
Ruby On Rails v5.2.4.3
MySQL v5.6

Refer to the contents </ font>

I ran the command and looked at the contents as follows.

I'm accessing a table called "Attachment".

[6] pry(main)> >> image_data = Attachment.find(7)
image_data = Attachment.find(7)
  Attachment Load (0.5ms)  SELECT  `attachments`.* FROM `attachments` WHERE `attachments`.`id` = 7 LIMIT 1
=> #<Attachment:0x00007f86e6d7b760
 id: 7,
 knowledge_id: 17,
 sub_id: "1",
 name: "test.png ",
 width_size: "1200",
 height_size: "799",
 file_type: "png",
 file_size: "72297",
 image: "test.png ",
 thumb_image_url:
  "/uploads/tmp/1593690046-968881373703887-0012-2842/thumb_test.png ",
 created_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
 updated_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
 image_url: "/uploads/tmp/1593690046-968881373703887-0012-2842/test.png ">

Here is the image information. </ font>

[7] pry(main)> >> image_data.image
image_data.image
=> #<ImageUploader:0x00007f86e6c26a68
 @cache_id=nil,
 @file=
  #<CarrierWave::SanitizedFile:0x00007f86e6c25e10
   @content=nil,
   @content_type=nil,
   @file=
    "/Users/ichikawadaisuke/projects/krown/public/uploads/attachment/image/7/test.png ",
   @original_filename=nil>,
 @filename=nil,
 @format=nil,
 @identifier="test.png ",
 @model=
  #<Attachment:0x00007f86e6d7b760
   id: 7,
   knowledge_id: 17,
   sub_id: "1",
   name: "test.png ",
   width_size: "1200",
   height_size: "799",
   file_type: "png",
   file_size: "72297",
   image: "test.png ",
   thumb_image_url:
    "/uploads/tmp/1593690046-968881373703887-0012-2842/thumb_test.png ",
   created_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
   updated_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
   image_url: "/uploads/tmp/1593690046-968881373703887-0012-2842/test.png ">,
 @mounted_as=:image,
 @staged=false,
 @storage=
  #<CarrierWave::Storage::File:0x00007f86e6c262c0
   @cache_called=nil,
   @uploader=#<ImageUploader:0x00007f86e6c26a68 ...>>,
 @versions=
  {:thumb=>
    #<ImageUploader::Uploader70108727518060:0x00007f86e6c25c80
     @cache_id=nil,
     @file=
      #<CarrierWave::SanitizedFile:0x00007f86e6c25460
       @content=nil,
       @content_type=nil,
       @file=
        "/Users/ichikawadaisuke/projects/krown/public/uploads/attachment/image/7/thumb_test.png ",
       @original_filename=nil>,
     @filename=nil,
     @format=nil,
     @identifier="test.png ",
     @model=
      #<Attachment:0x00007f86e6d7b760
       id: 7,
       knowledge_id: 17,
       sub_id: "1",
       name: "test.png ",
       width_size: "1200",
       height_size: "799",
       file_type: "png",
       file_size: "72297",
       image: "test.png ",
       thumb_image_url:
        "/uploads/tmp/1593690046-968881373703887-0012-2842/thumb_test.png ",
       created_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
       updated_at: Thu, 02 Jul 2020 11:40:46 UTC +00:00,
       image_url:
        "/uploads/tmp/1593690046-968881373703887-0012-2842/test.png ">,
     @mounted_as=:image,
     @parent_version=#<ImageUploader:0x00007f86e6c26a68 ...>,
     @staged=false,
     @storage=
      #<CarrierWave::Storage::File:0x00007f86e6c25a00
       @cache_called=nil,
       @uploader=
        #<ImageUploader::Uploader70108727518060:0x00007f86e6c25c80 ...>>,
     @versions={}>}>
[8] pry(main)> 

Furthermore, you can easily get the information of the object with one liner. </ font>

[9] pry(main)> >> image_data.image.file
image_data.image.file
=> #<CarrierWave::SanitizedFile:0x00007f86e6c25e10
 @content=nil,
 @content_type=nil,
 @file=
  "/Users/ichikawadaisuke/projects/krown/public/uploads/attachment/image/7/test.png ",
 @original_filename=nil>
[10] pry(main)> 


This time is over.

Recommended Posts