Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image upload error in Safari: Failed to load resource: Request header field Authorization is not allowed by Access-Control-Allow-Headers. #431

Open
netwire88 opened this issue Jan 23, 2021 · 1 comment
Assignees

Comments

@netwire88
Copy link

Hi,
I'm getting an error Failed to load resource: Request header field Authorization is not allowed by Access-Control-Allow-Headers. in Safari, but not in Chrome using the following code for javascript upload. Is there anyway to fix this?

<%= cl_image_upload_tag(:image_id, :upload_preset => "logos", :public_id => "#{@account.id.to_s}") %>

<%= cloudinary_js_config %>

<script type="text/javascript">

    $('.progress').hide();

    $(document).ready(function() {
        if($.fn.cloudinary_fileupload !== undefined) {
            $("input.cloudinary-fileupload[type=file]").cloudinary_fileupload({
              maxFileSize: 10000000,
              acceptFileTypes: /(\.|\/)(jpe?g|png)$/i
            });
        }

        $('.cloudinary-fileupload').bind('cloudinarydone', function(e, data) {
            $('.logo-thumbnail').hide();
            $('.preview').html(
                $.cloudinary.image(data.result.public_id,
                    { format: data.result.format, version: data.result.version,
                        crop: 'fit', width: 500, height: 200 })
            );
            $('.image_public_id').val(data.result.public_id);
            return true;
        });

        $('.cloudinary-fileupload').bind('cloudinaryprogress', function(e, data) {
            $('.progress').show();
            $('.progress-bar').css('width', Math.round((data.loaded * 100.0) / data.total) + '%');
        });

    });

</script>
@michalkcloudinay
Copy link

Hi @netwire88, This seems like a CORS error. Since direct uploading from the browser is performed using XHR (Ajax XMLHttpRequest‎) CORS requests. In order to support older browsers that do not support CORS, you can place cloudinary_cors.html in the public folder of your Rails application. This file is available in the vendor/assets/html folder of the Ruby gem. Let us know if this solves your issue.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants