CarrierWave에 저장된 데이터의 내용을 기준으로 합니다.

4615 단어 carrierwaveRubyRails

조사의 배경


Carrier Wave가 이미지 데이터를 올렸는데 그 데이터를 업데이트하려고 할 때 어떻게 데이터가 들어오는지 조사했다.
(이 기사를 본 사람도 있고 인용될 수도 있다)
데이터베이스에 파일 이름만 표시(image 열)

DB의 UI는 "sequelpro"를 사용합니다.열 값에 대한 세부내용을 보더라도 파일 이름에만 적용됩니다.

컨디션


항목
컨텐트
OS.Catalina
v10.15.4
Ruby
v2.5.1
Ruby On Rails
v5.2.4.3
MySQL
v5.6

컨텐트 참조


아래와 같이 명령을 수행하고 내용을 참조했다.
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">
다음은 이미지 정보입니다.
[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)> 

또한 쓰기 도구를 통해 개체 정보를 쉽게 얻을 수 있습니다.
[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)> 


이번에는 이게 다야.

좋은 웹페이지 즐겨찾기