Skip to main content

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

Comments

7 comments

  • kye

    Binary_content is unclear

    0
  • Roee Ben Ari

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

    0
  • Kathy Smith

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

    0
  • 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
  • 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
  • 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
  • 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

Please sign in to leave a comment.