Skip to content Skip to sidebar Skip to footer

Angularjs Put Method To Upload Files Gives No Data

I have a Symfony application that uses AngularJS on the front-end to upload files with ajax via the POST method. Working POST Method The data is added as FormData and some angular

Solution 1:

After delving further into this it appears this is a core PHP issue rather than a bug in AngularJS or Symfony.

The issue is that PHP PUT and PATCH do not parse the request so the content simply isn't available. (You can read more here: https://bugs.php.net/bug.php?id=55815)

A workaround to this is using the POST method but spoofing the method to be that of PATCH/PUT like so:

$scope.fileUpload = function (file) {
    var fd = new FormData();
    fd.append("title", file.title);
    fd.append("file", $scope.file);
    fd.append('_method', 'PUT');

    $http.post('example/update', fd, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined}
    }).then({
        // do something
    });
};

Post a Comment for "Angularjs Put Method To Upload Files Gives No Data"