abritopach / ionic-surveyjs

Sample project that shows how to integrate SurveyJS in Ionic APP.
MIT License
28 stars 18 forks source link

surveyjs question type upload is not working #6

Open bedinsky opened 5 years ago

bedinsky commented 5 years ago

Hi, did you ever tested a survey with a question type upload ?

The input field of type "file" is rendered in the ionic app (android and ios), it opens a filemanager but chosen image is not uploaded to surveyjs backend.

I think that the angular component Survey (from 'survey-angular') is not suited for an hybrid app.

File upload in ionic should be done using a cordova plugin file transfer see https://ionicframework.com/docs/native/file-transfer/

Do you think it is possible override existing Javascript function in 'survey-angular.js' ?

    dxSurveyService.prototype.sendFile = function (postId, file, onSendFile) {
        var xhr = new XMLHttpRequest();
        xhr.onload = xhr.onerror = function () {
            if (!onSendFile)
                return;
            onSendFile(xhr.status == 200, JSON.parse(xhr.response));
        };
        xhr.open("POST", dxSurveyService.serviceUrl + '/upload/', true);
        var formData = new FormData();
        formData.append("file", file);
        formData.append("postId", postId);
        xhr.send(formData);
    };