Monday 12 June 2017

Redirecting after upload

I'm trying to redirect after a file upload but when I try to redirect on AngularJS side, it is not working.

Node.js :

app.post('/upload', upload.single('propt'), function (req, res) { 
 res.send();
});

AngularJS :

$scope.uploadFile = function () {
        var fichier = $scope.monFichier;
        var uploadUrl = "/upload";
        console.dir(fichier);
        var fd = new FormData();
        fd.append('file', fichier);
        $http.post(uploadUrl, fd, {
            transformRequest: angular.identity,
            headers: { 'Content-Type': "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }
        })
            .then(function () {
                $location.path = '/users';
             });

    }

After the upload I'm on the page with url /upload and the error in the console :

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.



via Tewan

No comments:

Post a Comment