Hello i am creating an api and using Paperlcip and Base64 to upload images.
Here is my method. I want each file to be called avatar.(image_type).
How do i get the image_type?
Here is the code.
9: def set_image(image_as_base64)
=> 10: binding.pry
11: file = Paperclip.io_adapters.for(image_as_base64)
12: file.original_filename = "avatar.gif"
13: self.avatar = file
14: end
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)> image_as_base64
=> "data:image/gif;base64,R0lGODlhZABkAPABAAAAAP///yH5BAAAAAAALAAAAABkAGQAAAL+hI+hy+jAYnhJLnrsxVBP7n1YyHVaSYIeuqqna7Hv2NIzldoxLMm73uNFfEHgUNhAboxJ5hJXg94eOenPWsQenQriVtsEP6lR8tRRNV/VWfbXHYaP0WX6uXLPhOr4td3f1/YnGPg2aFgYd6iYONfYpQTJJSImWUkpZ5mJueiol2eQ1qk5yvlo+gmYSriK2Mr46hnKF0t66gU7C2qiqtvLy+obDOwqXEyciyyrbFuLapwsehv5zFwt7VyCu4wNzU3r3Rx+DW69LW5OfU6+250+uR6vPg9Pfylfn39vv4m/r9+PXyl/AQEOFDjNYMJ/DAs2PKjQmbuJ5Si2q4jxosb+XxY5ZvS4cVhHkR9Jhjw2EmVJlSejrXTZ8ltMdClhgrxpEidLnTZz+tz5syfQYwQhPlzoMKlRpUiXOm0KNRtCqRHHFY1qdWrWqu+OUvW6FWxXpl/JhjU79mlZtWfZpsX6di3cmjL3BK17l+ZLvEOF+uX7V+9MdjwBGxZcGHFewouvyn3cdu5exX0PM65MOfBlzY4jQ47rOTTo0XTRdSY9ebPl06VVZ16tFfVg1qlpz47d2nZi17x1N8ZdG/htrrmF7/aNuTe14sSDNx8ulnl059Oho5V+nXp2626xd9f+nbtk8Z+9jz9u/Pdz9Nqqs3evHn5y5JzTz7dff3387e9C+e8P3x+A/503YHngEXiffgnKlx+DdimnYIP+LTihhAJSeKGFCGpoIHmimddhgBvCFiGJDr6GIoQnqlihiS2meFoBADs="
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)> file = Paperclip.io_adapters.for(image_as_base64)
=> Paperclip::DataUriAdapter: data
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)> file.original_filename = "avatar.gif"
=> "avatar.gif"
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)> self.avatar = file
=> Paperclip::DataUriAdapter: avatar.gif
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)> self
=> #<Profile:0x007f9eabb58f00
id: 657,
user_id: 378,
birthday: Tue, 29 Apr 2003,
bio: "Quo incidunt labore et et et. Ea quasi cupiditate ipsam aut. Dolore nihil libero quia ipsum.",
phone: "(899) 372-6477",
address_line_1: "Bobby Freeway",
address_line_2: "Llewellyn Shoal",
suburb: "New Ryann",
state: "Utah",
postcode: "70026",
country_code: "PE",
first_name: "Pansy",
last_name: "Medhurst",
avatar_file_name: "avatar.gif",
avatar_content_type: "image/gif",
avatar_file_size: 617,
avatar_updated_at: Thu, 03 Mar 2016 23:50:26 UTC +00:00>
4.2.5.1@2.2.4 (#<Profile:0x007f9eabb58f00>)>
Aucun commentaire:
Enregistrer un commentaire