117
rated 0 times
[
123]
[
6]
/ answers: 1 / hits: 21662
/ 6 Years ago, wed, august 22, 2018, 12:00:00
Every fetch API example on the internet shows how to return only the body using response.json(), response.blob() etc.
What I need is to call a function with both the content-type and the body as a blob and I cannot figure out how to do it.
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);
});
This obviously doesn't work: data.contentType is filled, but data.raw is a promise. How can I get both values in the same context?
More From » promise