互联网上的每个提取API示例都展示了如何使用response.json(),response.blob()等仅返回主体。我需要的是同时调用内容类型和主体为blob的函数,而我无法弄清楚该怎么做。
fetch("url to an image of unknown type")
.then((response) => {
return {
contentType: response.headers.get("Content-Type"),
raw: response.blob()
})
.then((data) => {
imageHandler(data.contentType, data.raw);
});
Run Code Online (Sandbox Code Playgroud)
这显然行不通:data.contentType已填充,但data.raw是一个承诺。如何在相同的上下文中获得两个值?