如何在AngularJs中将$ http的reponseType设置为blob? [英] How to set reponseType as blob for $http in AngularJs?

查看:591
本文介绍了如何在AngularJs中将$ http的reponseType设置为blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将响应类型的角度设置为"blob". 如何在angularjs中为$ http设置响应类型? 下面提供了使用XMLHttpRequest设置responseType的示例代码.我需要将XMLHttpRequest替换为$ http.

i need to set response Type as 'blob' in angular. how to set response Type for $http in angularjs? sample code for set responseType using XMLHttpRequest is provided below. i need to replace XMLHttpRequest with $http.

var oMyForm = new FormData();
oMyForm.append("js", content);
var oReq = new XMLHttpRequest({mozSystem: true});
oReq.open("POST", url, true);
oReq.responseType = "blob";
oReq.onload = function(xhr) {

};
oReq.onerror = function(xhr) {

};
oReq.send(oMyForm);

推荐答案

angular为此提供了配置对象,请检查文档

angular provides config object for that , check docs

  $http({
        url: "http://localhost:8080/example/teste",
        method: "POST",
        responseType: "blob"

    })

这篇关于如何在AngularJs中将$ http的reponseType设置为blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆