Question

I've successfully followed Soundcloud's API documentation but hit an error that's got me stuck.

When uploading / posting a file using their example I have no trouble when I hard code a file on my local machine. What I really want to do is transfer files stored on S3. This kept failing with an Errno::ENOENT - No such file or directory error. Open-URI is included and I tested it by hardcoding a file available to the public on another server and it still fails. So I don't feel the problem is with S3 or my generate_secure_s3_url for that reason and because I successfully use my generate_secure_s3_url elsewhere.

My code is as follows, can anyone help?

def product_tracks_to_soundcloud(access_token)
  require 'soundcloud'
  require 'open-uri'
  # create a client object with access token
  client = Soundcloud.new(:access_token => access_token)

    self.producttracklistings.each do |pt|
        filebase = URI.encode(pt.track.track_file_name, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
        fileurl = generate_secure_s3_url(filebase)
        # upload an audio file
    track = client.post('/tracks', :track => {
      :title => pt.track.name,
      :asset_data => File.new(fileurl, 'rb')
    })
    end
Was it helpful?

Solution

Ok, managed to figure this one out myself and it's annoyingly simply. Firstly at no point in the above am I actually calling upon Open-URI. Once I sussed that, it was then just a case of ammending this:

:asset_data => File.new(fileurl, 'rb')

to this:

:asset_data => open(fileurl)

I hope that is of help to others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top