1

I'm try to post a file using RestClient with Ruby on rails, I have try to conver below curl command:

curl -H 'Authorization: Bearer ACCESS_TOKEN' -F 'file=@FILE_PATH' https://api.com/api

When converting with RestClient like below:

res = RestClient::Request.new(
        method: :post,
        url: 'https://api.com/api',
        :payload => {
            :file => File.new("#{Rails.root}/public/Sample.docx" , 'rb')
        },
        :headers => {
            :Authorization => "Bearer 155c5e5c4feea51b386fdfe204abc60b7f4025fb91988519de869525217b4702",
            :content_type => "multipart/form-data"
        }
    )

    res.execute

On this code showing 400 Bad Request

What I'm doing wrong with this code?

Thanks

faul
  • 35
  • 8

1 Answers1

0

Your post is a duplicate of this one Ruby - Uploading a file using RestClient post

In your case, try changing content_type to application/vnd.openxmlformats-officedocument.wordprocessingml.document

List of MIME types can be found here: What is a correct mime type for docx, pptx etc?

Stephane Paquet
  • 2,315
  • 27
  • 31