Attach a blob to an input of type file in a form

后端 未结 2 2064
天涯浪人
天涯浪人 2021-02-12 11:04

How to append blob to input of type file?




        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-12 11:09

    I had a similar problem with a fairly complex form in an angular app, so instead of the form I just sent the blob individually using XMLHttpRequest(). This particular "blob" was created in a WebAudioAPI context, creating an audio track in the user's browser.

    var xhr = new XMLHttpRequest();
    xhr.open('POST', 'someURLForTheUpload', true); //my url had the ID of the item that the blob corresponded to
    xhr.responseType = 'Blob';
    xhr.setRequestHeader("x-csrf-token",csrf); //if you are doing CSRF stuff
    xhr.onload = function(e) { /*irrelevant code*/ };
    xhr.send(blob);
    

提交回复
热议问题