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
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.