[ckan-dev] CORS issue whe using CKAN API for creating resource

lucia.espona at wsl.ch lucia.espona at wsl.ch
Wed Apr 27 10:47:56 UTC 2016


 Dear all

I am new to CKAN and I have an issue I am not able to solve.

In the configuration file (.ini) of my CKAN instance (2.5.2) I have set the CORS configuration as follows:
ckan.cors.origin_allow_all = trueI am using the FileStore API for creating resources and SOMETIMES the CORS headers are missing in the response and the request fails: 
"Cross-Origin  Request Blocked: The Same Origin Policy disallows reading the remote  resource at http://ckan.wsl.ch/api/action/resource_create. (Reason: CORS  header 'Access-Control-Allow-Origin' missing)."
You can find below two example request I performed, one successful and the other failed, I haven't been able to identify the reason why. Could someone give me a hint how to fix this?

Many thanks in advance and best regards,
Lucia

*********************************************************************
****** Successful Request (file uploaded is a "plain text" xml)******

Request: http://ckan.wsl.ch/api/action/resource_create
   Header
    Accept    application/json, text/javascript, */*; q=0.01
    Accept-Encoding    gzip, deflate
    Accept-Language    en-GB,en;q=0.5
    Content-Length    2487139    
    Content-Type    multipart/form-data; boundary=---------------------------32069285045071
    Host    ckan.wsl.ch
    Origin    http://envidat01.wsl.ch:8080
    Referer    http://envidat01.wsl.ch:8080/MetadataUpload/
    User-Agent    Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
    X-CKAN-API-Key    f1083246-********b3b7bd16

   form-data; 
           name="package_id"  6672445a-3fd7-40af-a47e-690c9b8c6b39
           name="id"  logo 
           name="url"   
           name="format"  PNG
           name="mimetype"  image/png 
           name="name"  logo 
           name="description"  Resource Created from MetadataUpload Webapp using the FileStore API 
           name="upload"; 
 
   filename="logo.png" Content-Type: image/png [....]

Response Headers:
    Access-Control-Allow-Head...    X-CKAN-API-KEY, Authorization, Content-Type
    Access-Control-Allow-Meth...    POST, PUT, GET, DELETE, OPTIONS
    Access-Control-Allow-Orig...    *
    Cache-Control    no-cache
    Connection    Keep-Alive
    Content-Length    836
    Content-Type    application/json;charset=utf-8
    Date    Wed, 27 Apr 2016 08:00:51 GMT
    Keep-Alive    timeout=5, max=96
    Pragma    no-cache
    Server    Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5



*********************************************************************
********** FAILED request (file uploaded is a "binary" png) *********
Request: http://ckan.wsl.ch/api/action/resource_create
   Header
     Accept    application/json, text/javascript, */*; q=0.01
      Accept-Encoding gzip, deflate
      Accept-Language  en-GB,en;q=0.5
      Content-Length   27875
      Content-Type    multipart/form-data; boundary=---------------------------16263549323323
      Host    ckan.wsl.ch
      Origin  http://envidat01.wsl.ch:8080
      Referer http://envidat01.wsl.ch:8080/MetadataUpload/
      User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0
      X-CKAN-API-Key f108324**************3b7bd16

   form-data; 
           name="package_id"  6672445a-3fd7-40af-a47e-690c9b8c6b39
           name="id"  logo 
           name="url"   
           name="format"  PNG
           name="mimetype"  image/png 
           name="name"  logo 
           name="description"  Resource Created from MetadataUpload Webapp using the FileStore API 
           name="upload"; 
 
   filename="logo.png" Content-Type: image/png [....]

Response Headers:
Connection    close
Content-Length 175
Content-Type   text/html; charset=utf8
Date    Wed, 27 Apr 2016 08:02:48 GMT
Server  Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5





_________________________________________________________
Dr. Lucia Espona Pernas

Swiss Federal Institute for Forest, Snow and Landscape Research WSL
Hauptgebäaude Labortrakt (HL D34)
Zürcherstrasse 111
8903 Birmensdorf
Switzerland

+41 44 739 28 71 phone direct
+41 44 739 21 11 reception

www.wsl.ch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20160427/a4c9ea77/attachment-0002.html>


More information about the ckan-dev mailing list