When using your own code to manually upload assets as opposed to using the Upload API, you must provide a valid file
parameter, as described in our upload parameters documentation.
The 'Invalid URL' response for uploads usually happens when the content of the file is not properly encoded.
One common cause for this response was because the upload method was given a StringIO object that did not have a filename attribute. If this is the case, try to do something like the following (in Python):
contents_temp = StringIO.StringIO(binary_content) contents_temp.name = 'file' result = cloudinary.uploader.upload(contents_temp)
Otherwise, please double check your file
by logging the value and make sure it is valid. In the event that you still require assistance, please open a support ticket so that we can assist you.
Comments
7 comments
Binary_content is unclear
Binary_content should contain a byte array buffer. Please see:
https://docs.python.org/2/library/stringio.html
I've also experienced this error when there were unicode characters in the file name (in this case an em-dash)
I get this error when using the Ruby gem. Ruby StringIO does not have a `name` attribute. What is the solition when using Ruby?
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?
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.
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?
Please sign in to leave a comment.