0

I have this code for image uploading:

$scope.uploadAvatar = function(e) {
    $scope.uploadAvatarError = false;
    $scope.uploadAvatarSuccess = false;
    var f = document.getElementById('uploadAvatar').files[0],
        fd = new FormData();
    if (!f) {
        return
    }

    fd.append('user', $scope.user.user_email);
    fd.append('photo', f);

    $http.post(apiUrl + 'addProfilePicture', fd, {
        transformRequest: angular.identity,
        headers: {'Content-Type': undefined}
    }).then(function(response){
        console.log(response);
    })
}

When I send it to server, it returns status 200, but nothing is uploaded. In network tab in chrome dev tools it says ContentType application/json instead of multipart/form-data. How can I change that?

3

1 Answer 1

0

You can use the very thorough angular-file-upload module to achieve that. If I may, you can even add the preview with this module, which can be useful / nice in case of avatars.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.