Upload a file #26
Replies: 5 comments
-
Google Group Date: Fri, 23 Jun 2017 18:14:34 -0400 I haven’t confirmed this, but I suspect your use of With that said, you likely want a before_create and before_update hook, that receives the Rack file upload object, moves the tempfile somewhere permanent, and updates the record with that location. Alternatively you could use something like Shrine which will abstract away some of this.
|
Beta Was this translation helpful? Give feedback.
-
Google Group Date: Fri, 23 Jun 2017 16:31:44 -0700 On Friday, June 23, 2017 at 12:37:42 PM UTC-7, Kenneth Leung wrote:
You probably have to add the following to your AutoForme configuration for form_attributes(:enctype=>'multipart/form-data') Otherwise you can't handle uploaded files. Thanks, |
Beta Was this translation helpful? Give feedback.
-
Google Group Date: Fri, 23 Jun 2017 16:43:28 -0700 Hi Adam, "File :file" is a blob datatype. reference According to this post On Friday, June 23, 2017 at 3:14:36 PM UTC-7, Adam Daniels wrote:
|
Beta Was this translation helpful? Give feedback.
-
Google Group Date: Fri, 23 Jun 2017 19:57:38 -0400 Ah, you’re right! I should of looked at the docs as it’s vaguely familiar now. Glad you got it sorted.
|
Beta Was this translation helpful? Give feedback.
-
Google Group Date: Fri, 23 Jun 2017 16:58:02 -0700 Thank you Jeremy. Your suggestion solved my problem. For future reference. module Template
... now my model LetterTemplate#file= received a hash like this: {"filename"=>"filename.docx", with these information, LetterTemplate#file= could handle the uploaded file Kenneth On Friday, June 23, 2017 at 4:31:45 PM UTC-7, Jeremy Evans wrote:
|
Beta Was this translation helpful? Give feedback.
-
Google Group Post: https://groups.google.com/g/ruby-forme/c/AoPkpbu9944
Google Group Date: Fri, 23 Jun 2017 12:37:42 -0700
Google Group Sender: alpha...@gmail.com
Hi,
I have a schema as such:
create_table(:letter_templates) do
primary_key :id
column :uuid, 'uniqueidentifier'
String :name
TrueClass :active, :default => true
Date :created_at
File :file
end
And a Sinatra app:
module Template
class App < Sinatra::Base
...
end
And a model:
class LetterTemplate < Sequel::Model
plugin :uuid, :field => :uuid
plugin :timestamps
def file=(info)
...
end
end
The problem is at the file= method. "info" is expected to be a hash (session/@params), but it's receiving a string (the filename) instead.
Therefore, the file= method cannot handle the file upload.
Any idea on how to tell Autoforme to send session data to LetterTemplate#file= ?
Thank you for your help.
Kenneth
Beta Was this translation helpful? Give feedback.
All reactions