@@ -30,8 +30,8 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
3030 this . _form = this . $ ( 'form' ) ;
3131 // this._origin = $('#field-image-upload');
3232 // this._file = this._origin.clone()
33- this . _file = $ ( '#field-image-upload' ) ;
34- this . _url = $ ( '#field-image-url' ) ;
33+ this . _file = $ ( '#field-image-upload, #field-resource-upload ' ) ;
34+ this . _url = $ ( '#field-image-url, #field-resource-url ' ) ;
3535 this . _save = $ ( '[name=save]' ) ;
3636 this . _id = $ ( 'input[name=id]' ) ;
3737 this . _progress = $ ( '<div>' , {
@@ -47,6 +47,8 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
4747 this . _pressedSaveButton = null ;
4848
4949 var self = this ;
50+ var csrf_field = $ ( "meta[name=csrf_field_name]" ) . attr ( "content" ) ;
51+ this . _frm_csrf_token = $ ( "meta[name=" + csrf_field + "]" ) . attr ( "content" ) ;
5052
5153 this . _file . fileupload ( {
5254 url : this . sandbox . client . url ( '/api/action/cloudstorage_upload_multipart' ) ,
@@ -59,7 +61,10 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
5961 progressall : this . _onFileUploadProgress ,
6062 done : this . _onFinishUpload ,
6163 fail : this . _onUploadFail ,
62- always : this . _onAnyEndedUpload
64+ always : this . _onAnyEndedUpload ,
65+ headers : {
66+ "X-CSRFToken" : this . _frm_csrf_token ,
67+ } ,
6368 } ) ;
6469
6570 this . _save . on ( 'click' , this . _onSaveClick ) ;
@@ -320,7 +325,7 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
320325 var id = this . _id . val ( ) ;
321326 var self = this ;
322327 if ( this . _uploadId === null )
323- this . _onPrepareUpload ( file , id ) . then (
328+ this . _onPrepareUpload ( file , id , this . _frm_csrf_token ) . then (
324329 function ( data ) {
325330 self . _uploadId = data . result . id ;
326331 self . el . trigger ( 'multipartstarted.cloudstorage' ) ;
@@ -335,7 +340,7 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
335340
336341 } ,
337342
338- _onPrepareUpload : function ( file , id ) {
343+ _onPrepareUpload : function ( file , id , csrf ) {
339344
340345 return $ . ajax ( {
341346 method : 'POST' ,
@@ -344,7 +349,10 @@ ckan.module('cloudstorage-multipart-upload', function($, _) {
344349 id : id ,
345350 name : encodeURIComponent ( file . name ) ,
346351 size : file . size
347- } )
352+ } ) ,
353+ headers : {
354+ "X-CSRFToken" : csrf ,
355+ } ,
348356 } ) ;
349357
350358 } ,
0 commit comments