Why do I get an "Invalid URL" message when trying to upload?

Follow

Comments

7 comments

  • Avatar
    Roee Ben Ari

    Binary_content should contain a byte array buffer. Please see:
    https://docs.python.org/2/library/stringio.html

    0
    Comment actions Permalink
  • Avatar
    Romerike Jujutsu Klubb

    I get this error when using the Ruby gem.  Ruby StringIO does not have a `name` attribute.  What is the solition when using Ruby?

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi,

    Thanks for providing these additional details.

    The upload and upload_large were updated a few versions ago to better standardise the handling as part of a different issue. - https://github.com/cloudinary/cloudinary_gem/pull/260

    Essentially, your code with upload should work as the StringIO class has a read method which is what the upload method - https://github.com/cloudinary/cloudinary_gem/blob/master/lib/cloudinary/uploader.rb#L75

    Generally, for files below 100MB the upload method can be used but above that upload_large is recommended. Although I suspect in your example the file is less than 100MB in any case.

    Do you get any errors when using the code you shared? If you do, may I please ask you to share the error, and also which gem version you're using?

    0
    Comment actions Permalink
  • Avatar
    kye

    Binary_content is unclear

    0
    Comment actions Permalink
  • Avatar
    Romerike Jujutsu Klubb

    Hi, thanks for the reply!

    Here is what I tried.  The `image` object is an ActiveRecord object, and `content_data_io` returns a StringIO object.  If I switch to `upload_large`, everything works fine, and this is an acceptable solution for me.  Going through the code, I see that `upload`and `upload_large` have slightly different checks on the `file` parameter.  I believe they should behave the same and that `upload_large` is correct and `upload` should be corrected.

    result = Cloudinary::Uploader.upload(
    image.content_data_io,
    resource_type: image.video? ? 'video' : 'image',
    public_id: "#{Rails.env}/images/#{image.id}"
    )

     

    0
    Comment actions Permalink
  • Avatar
    Aleksandar Kostadinov

    Hi @Romerike Jujutsu Klubb,

    As the error mentions this is due to the StringIO class not having this attribute. In general, you won't actually need to use this approach when uploading your images. Could you please share more details regarding where you are getting the files and how (sample code) you are currently attempting to upload them that lead you to use the above-mentioned approach?

    0
    Comment actions Permalink
  • Avatar
    Richard Yarwood

    I've also experienced this error when there were unicode characters in the file name (in this case an em-dash)

    0
    Comment actions Permalink

Please sign in to leave a comment.