0

I have an articles model to which I want to add images, using active storage installed for uploading images via the form. Active storage works fine, both locally and in production with upload to Amazon s3.

However, I'm also using froala. When trying to insert an image to froala editor, I get this error (in the browser) : XHR OPTIONS https://undefined.amazonaws.com/undefined

article_controller.rb

  def nouveau                         # new
    @auteur = Auteur.find(session[:auteur])
    @article = Article.new
    @auteur.articles.build
    options = {
      bucket: '',                    # my bucket
      region: 'eu-west-1',
      keyStart: 'uploads',
      acl: 'public-read',            # I **think** this is correct
      accessKey: '',                 # my access key, like active storage
      secretKey: ''                  # my secret key, like active storage
    }
    @aws_data = FroalaEditorSDK::S3.data_hash(options)
  end

the javascript that goes with it:

var editor = new FroalaEditor('#article_contenu',{
                              height: 330,
                              iframeStyleFiles: ['fr_moi.css'],
                              pluginsEnabled: ['image', 'link','align','charCounter','colors','fontAwesome','fontSize','fullscreen','image','link','lists','paragraphFormat','paragraphStyle','quote','url'],
                              placeholderText: 'Incipe scribere...',
                              paragraphFormat: {
                                  N: 'normal',
                                  H2: 'titre 2',
                                  H3: 'titre 3'
                                },
                              imageUploadToS3: '<%= @aws_data.as_json.html_safe %>',
                              toolbarButtons:
                               // and so on. The js file is working correctly

I get the something went wrong. Please try again message in the froala editor. Browser responds:

XHR OPTIONS https://undefined.amazonaws.com/undefined
 « Same Origin » policy doesn't allow consulting the distant resource on https://undefined.amazonaws.com/undefined. Reason : failure CORS request.

2 Answers 2

1

Try specifying a dns compliant bucket name which is used to generate the upload url. Hope you have created a bucket with certain permissions wich alow you to upload. replace region: with s3_region:

Sign up to request clarification or add additional context in comments.

Comments

0

Very strange what happened here. I had put the Javascript in a js file in app/assets. That didn't work (although the rest of the editor got loaded)

Only when I created a template for this with tag in the footer, it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.