无法将WAV文件上传到Soundcloud API

时间:2014-08-21 20:08:32

标签: ruby-on-rails ruby soundcloud

def upload_to_soundcloud
    p params
    @client = Soundcloud.new(:access_token => current_user.access_token)
    p @client
    track = @client.post('/tracks', :track => {
        :title => 'songName',
        :asset_data => params['songFile']
        })
    p track
end 

p params:

Parameters: {"songFile"=>#<ActionDispatch::Http::UploadedFile:0x007fd4a7ba64d0 @original_filename="blob", @content_type="audio/wav", @headers="Content-Disposition: form-data; name=\"songFile\"; filename=\"blob\"\r\nContent-Type: audio/wav\r\n", @tempfile=#<Tempfile:/var/folders/fy/0hq5vn9938v5r777d_3ty0lh0000gn/T/RackMultipart20140821-83090-1c8gkb2>>}

p @client:

#<SoundCloud::Client:0x007fd4aa05bf00 @options={:site=>"soundcloud.com", :on_exchange_token=>#<Proc:0x007fd4a3e6a4b8@/Users/darrendahl/.rvm/gems/ruby-2.0.0-p481/gems/soundcloud-0.3.2/lib/soundcloud/client.rb:11 (lambda)>, :access_token=>"--- !ruby/hash:SoundCloud::HashResponseWrapper\naccess_token:{access_token}\nscope: non-expiring\n"}>

我从帖子跟踪请求中收到此错误:

  SoundCloud::ResponseError - HTTP status: 401 Unauthorized:
  soundcloud (0.3.2) lib/soundcloud/client.rb:152:in `handle_response'
  soundcloud (0.3.2) lib/soundcloud/client.rb:32:in `post'
  app/controllers/songs_controller.rb:22:in `upload_to_soundcloud'
  actionpack (3.2.13) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:167:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
  activesupport (3.2.13) lib/active_support/callbacks.rb:414:in `_run__629916066604458588__process_action__2865853734394445716__callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.13) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
  activesupport (3.2.13) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.13) lib/abstract_controller/callbacks.rb:17:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `block in instrument'
  activesupport (3.2.13) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (3.2.13) lib/active_support/notifications.rb:123:in `instrument'
  actionpack (3.2.13) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
  actionpack (3.2.13) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
  activerecord (3.2.13) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (3.2.13) lib/abstract_controller/base.rb:121:in `process'
  actionpack (3.2.13) lib/abstract_controller/rendering.rb:45:in `process'
  actionpack (3.2.13) lib/action_controller/metal.rb:203:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
  actionpack (3.2.13) lib/action_controller/metal.rb:246:in `block in action'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:36:in `call'
  journey (1.0.4) lib/journey/router.rb:68:in `block in call'
  journey (1.0.4) lib/journey/router.rb:56:in `call'
  actionpack (3.2.13) lib/action_dispatch/routing/route_set.rb:612:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
  rack (1.4.5) lib/rack/etag.rb:23:in `call'
  rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/head.rb:14:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in `call'
  rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
  rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in `call'
  activerecord (3.2.13) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
  actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.13) lib/active_support/callbacks.rb:405:in `_run__405240541142666585__call__4563851468004131522__callbacks'

这是在我成功登录并将soundcloud访问令牌对象存储在我的数据库中之后。 current_user.access_token部分返回访问令牌。

有没有其他人有这个问题?我不确定它是否与oauth和身份验证有关,或者是否从从asset_data上传的对象类型中抛出错误。该文件非常小,因此不应该是因为文件大小。是否只有某些类型的对象可以上传?我尝试在ActionDispatch对象中使用tempfile但遇到了同样的错误。

我能够使用api登录soundcloud,并且获取用户信息的请求有效,但不是这样。谢谢!

1 个答案:

答案 0 :(得分:0)

如果我正确阅读Soundcloud API Auth via Golang 401 Error,您在成功登录后获得了一个访问令牌,用于进一步的通话,例如您的帖子请求,也许您可​​以尝试一下?