T
T
Tortway2018-09-06 01:10:28
Ruby on Rails
Tortway, 2018-09-06 01:10:28

How to upload file to server without using form helpers?

I'm using ruby-hyperloop , because of which the client code is written in .rb files, so the form for uploading files to the server must be executed without helpers, which are only available for Action View.

I do this (using ruby-hyperloop)
FORM(action: '/library', method: 'post') do
  INPUT(name: 'book_file', type: 'file')
  BUTTON(type: 'submit') { 'Upload' }
end

As a result, the form looks like this:
<form action="/library" method="post">
  <input name="book_file" type="file" />
  <button type="submit">Upload</button>
</form>

I meet the server like this:
def create
    book_file = params[:book_file].inspect
    puts '------------'
    puts book_file
    puts '------------'
    ...
  end

But only the file name is passed:
yrs7Sh3.png
And I expected that there would be an object with all the data of the file, which would eventually allow me to upload this file to the server.
Why is this happening? How to make upload correctly without using helpers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artur Bordenyuk, 2018-09-06
@Tortway

It's not about the helpers, it's about the form itself. She also needs to specify enctype="multipart/form-data"
Read more about the enctype attribute on htmlbook

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question