thelastone
thelastone

Reputation: 45

Can't upload audio file to Cloudinary using Rails

I'm trying to add the audio file to Cloudinary storage. I got stuck when error show:

CloudinaryException (Invalid resource type audio):
app/controllers/musics_controller.rb:23:in `create'

I've added configuration in my Music.rb file from another help in stack overflow:

has_attached_file :song, :storage => :cloudinary, path: 'muvent/musics/:filename', :cloudinary_resource_type => :audio
validates_with AttachmentSizeValidator, attributes: :song, less_than: 10.megabytes
validates_attachment_content_type :song, :content_type => [ 'application/octet-stream', 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio' ]

But, I still can't upload the file to Cloudinary. I also added permit for song column in my controller music_params which the error come. How can I fix this?

Update

I've fixed the error above. But why another error in logs server show file -b --mime in rails? Gemfile I use in here paperclip and paperclip-cloudinary.

Upvotes: 0

Views: 436

Answers (1)

Roee Ben-Ari
Roee Ben-Ari

Reputation: 610

Please make sure to use the right resource_type (a Cloudinary parameter) according to the file's type. The default resource type is image. Set it to video when uploading audio/video files or raw when uploading non-media files (such as doc,csv,css,js, etc).

Upvotes: 1

Related Questions