I want to upload a file with jquery-file-upload (blueimp) in cross domain to a symfony2 application.
To do this, client side :
SLjQuery(function () {
'use strict';
SLjQuery('#media_answer_answer').fileupload({
url: "http://recrutonline.dev/app_dev.php/api/media/questionnaire-test-media/uploads",
dataType: 'text',
formData: SLjQuery('form#answer_process_form').serializeArray(),
forceIframeTransport: true,
redirect: 'http://mywebsite.dev/result.html?%s',
done: function (e, data) {
console.log('upload ok ', data)
},
progressall: function (e, data) {
console.log(data.loaded/data.total);
var progress = parseInt(data.loaded / data.total * 100, 10);
SLjQuery('#progress .progress-bar').css(
'width',
progress + '%'
);
}
}).prop('disabled', !SLjQuery.support.fileInput)
.parent().addClass(SLjQuery.support.fileInput ? undefined : 'disabled')
;
});
in my controller symfony :
public function postMediaUploadAction(Request $request)
{
$requestData = $request->request->all();
$redirectResponse = $requestData['redirect']; // http://mywebsite.dev/result.html?%s
//...
//here process on data & get file uploaded
//...
//example of data I would send back to the client : http://mywebsite.dev/result.html?{'file':[{'name':'filetoupload.jpg'}]}
$response = str_replace("%s", "{'file':[{'name':'filetoupload.jpg'}]}", $redirectresponse); // is it the good method ?
return ??
}
Now client side response received :
in console.log of 'done' parameter of ajax function:
data.result -> undefined
data.textStatus -> "success"
I tried to return many things but result is still undefined. So do you know what kind of data I have to return ?