How do you POST a FormData object in Angular 2?

前端 未结 4 1874
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 22:27

I need to upload a file and send some json along with it, I have this function:

POST_formData(url, data) {
        var headers = new Headers(), authtoken = l         


        
4条回答
  •  不思量自难忘°
    2020-12-07 22:57

    It's an Open Isuue on Angular2 Git Repository, and there is also a Pull Request waiting to be merged, hope that it will be merged soon.


    Alternatively,

    You can use XMLHttpRequest Object directly, for that.

    And don't forget to set the header

    xhr.setRequestHeader("enctype", "multipart/form-data");
    
    // IE workaround for Cache issues
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Cache-Control", "no-store");
    xhr.setRequestHeader("Pragma", "no-cache");
    

    on the XMLHttpRequest that you make.


    Similar Questions:

    How to upload file in Angular2

    Angular 2 File upload from input type=file

    Angular2 post uploaded file

提交回复
热议问题