我在嘗試將新曲目發佈到Soundcloud時尋求一些幫助。我已成功驗證用戶身份,但也許遇到了麻煩,可能是我嘗試發佈曲目時發送給Soundcloud的數據格式。這裏是我的代碼:在向Soundcloud發佈新曲目時遇到問題,422
client = Soundcloud.new(:access_token => current_user.access_token)
sound = params[:sc_upload][:sound]
title = params[:title]
track = client.post('/tracks', track: {
:title => title,
:asset_data => File.new(sound.tempfile.path, 'rb')
})
期待不同的反應,我又試圖存儲在公共/上傳文件,然後訪問它,就像這樣:
track = client.post('/tracks', track: {
:title => title,
:asset_data => open(Rails.root.join('public', 'uploads', sound.original_filename).to_s)
})
接收,仍然是422錯誤,我想這爲了好玩:asset_data:聲音,其中聲音是ActionDispatch :: Http :: UploadedFile <對象。 http://api.rubyonrails.org/classes/ActionDispatch/Http/UploadedFile.html
sound = #<ActionDispatch::Http::UploadedFile:0x007f922c55c920 @content_type="audio/x-wav", @headers="Content-Disposition: form-data; name=\"sc_upload[sound]\"; filename=\"1980s-Casio-Violin-C5.wav\"\r\nContent-Type: audio/x-wav\r\n",
@original_filename="1980s-Casio-Violin-C5.wav", @tempfile=<File:/var/folders/h1/bhw9lw797d35shc2fkws70g00000gn/T/RackMultipart201505 8-2513-8r2tq7>>
我已經收到的SoundCloud :: ResponseError(HTTP狀態:422無法處理的實體)每次。我將不勝感激任何幫助。可能涉及:Can't post new track via PHP Soundcloud API。
謝謝。