Could Any one have solved this problem of COR in polymer?

1,146 views
Skip to first unread message

Chrispinus Onyancha

unread,
Nov 16, 2015, 6:57:02 AM11/16/15
to Eric Bidelman, David Waterman, Polymer



<dom-module id="upload-button">
<template>
<iron-ajax
id="advertURL"
    auto
    url="https:\\app-spot.com/get_upload_url"
    handle-as="json"
    method="GET"
    last-response="{{returned_url}}">
    </iron-ajax>
<iron-ajax
id="advertsub"
    auto="[[false]]"
    url="{{returned_url}}"
    handle-as="json"
    method="POST"
    params='{{params_advert}}'
    on-response="_returnedResp">
    </iron-ajax>

                <input hidden name="myupload" id="file" value="{{fileName::change}}" on-change="readURL" type="file" class="upload" />


        </template>
<script>
Polymer({
is:'upload-button',
​                
readURL: function(t) {
                       var e =t.srcElement;
                       var formData = new FormData();
                        for (var i = 0, f;  f= e.files[i]; ++i) {
                              formData.append(e.name, f,f.name);
                }
this.$.advertsub.body = formData;
this.$.advertsub.contentType = null;
        this.$.advertsub.generateRequest();
    },
    _returnedResp:function(e){
console.log(e.detail.response);
    }

       });
</script>
</dom-module>



WHEN I TRY TO select an image and sends i get.

XMLHttpRequest cannot load http://localhost:8080/_ah/upload/ahFwcmVjaXNlLXJheS05NDAwMHIiCxIVX19CbG9iVXBsb2FkU2Vzc2lvbl9fGICAgICAgIAJDA. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access.
add-advert.html:183 


HOW DO I HANDLE THIS?

My server uses the blobstore to handle the image.
I have even added the Access-Control-Allow-Origin on the server redirect header but still i failed.























Onyancha Chrispinus
Developer




santos...@gmail.com

unread,
Dec 7, 2015, 2:42:26 PM12/7/15
to Polymer, ebi...@gmail.com, davidmax...@gmail.com
Try this: https://benjaminhorn.io/code/setting-cors-cross-origin-resource-sharing-on-apache-with-correct-response-headers-allowing-everything-through/

I had similar issues until I made the setting: always set header.... along with the mod-rewrite rule so that the web server responds with 200 success as the API wasn't written to perform that.
Reply all
Reply to author
Forward
0 new messages