利用Blob从api返回的文件流下载文件

function downLoad(data){
    var url = window.serverIP+"/Document/BatchDownLoadPLMDocument";
    $.ajax({
        url,
        data:JSON.stringify(data),
        type:"POST",
        dataType:'binary',
        contentType: "application/json",
        xhrFields: {
            responseType: "blob"
        },
        headers:{"Authorization":"Bearer "+window.token,'Content-Type':'application/json','X-Requested-With':'XMLHttpRequest'},
        success:function(fileRes){
            let blob = new Blob([fileRes]);
            let src = window.URL.createObjectURL(fileRes);
            $('#photo').attr('src',src);
            document.getElementById('photoName').innerHTML = $d("workOrderSchedulePathDTO.materialName")+"("+$d("workOrderSchedulePathDTO.materialCode")+")";
            $('#photo').on("tap",function(){
                Mobile_NS.previewImg(src);
            });
            $('#photo').on("click",function(){
                Mobile_NS.previewImg(src);
            });
        },
        fail:function(fileRes){
            Mobile_NS.alert(fileRes);
            
        },
        complete: function(xhr){
            Mobile_NS.hideLoader();
        }
    });
}

 

上一篇:PAT (Basic Level) Practice 1048 数字加密 (20 分)


下一篇:程序的测量和计时