Comments (11)
does not work.
Indeed because $fetch
already consumes res data as text()
. @danielroe is working to improve blob handling. using fetch
is more a workaround :)
Could it be because banner.data is a dataurl?
BTW do you mind sharing server/api/mc/banners.ts
code? Might help to ensure changes fixes your usage properly.
from ofetch.
server/api/mc/banners.ts
is connected to a database. As I was already creating an example, I paste the link here.
If I use fetch, the blob is empty. You can see it in the codesandbox that you paste above.
from ofetch.
The issue is beyond ohmyfetch then๐ We also need to support
Blob
polyfill for Node.js (unjs/unenv#23) and probably some bits in h3 for response type (in your example you are returning a json array with base64 blob strings).I would appreciate it if you can move the issue to nuxt/framework to track support.
I am going to create a new issue there that makes a link to the two issues
from ofetch.
@frbuceta Apart from Blob support in ohmyfetch
, the issue you were experiencing is solved if you return a value from map
.
<template>
<pre>
{{ banners }}
</pre>
</template>
<script setup>
import _ from "lodash";
// eslint-disable-next-line
const { data: banners, refresh: bannersFetcher } = await useAsyncData(
"banners",
async () => {
const banners = await $fetch("/api/banners").then((data) => {
return Promise.all(
_.map(data, async (banner) => {
// const blob = await $fetch.raw(banner.data).then((res) => res.blob());
const blob = await fetch(banner.data).then((r) => r.blob());
console.log(blob);
+ return blob;
})
);
});
console.log(banners);
+ return banners;
}
);
</script>
from ofetch.
File
is not supported by Node: https://developer.mozilla.org/en-US/docs/Web/API/File
from ofetch.
Hi @frbuceta. $fetch
already consumes and parses body and returns body (not res
which can be accessed with $fetch.raw().then(res => res.blob)
). To manually consume blob you might want to use fetch().then(r => r.blob()
from ofetch.
Hi @frbuceta.
$fetch
already consumes and parses body and returns body (notres
which can be accessed with$fetch.raw().then(res => res.blob)
). To manually consume blob you might want to usefetch().then(r => r.blob()
await $fetch.raw(banner.data).then(res => res.blob())
does not work. Could it be because banner.data
is a dataurl?
from ofetch.
The issue is beyond ohmyfetch then๐
We also need to support Blob
polyfill for Node.js (unjs/unenv#23) and probably some bits in h3 for response type (in your example you are returning a json array with base64 blob strings).
I would appreciate it if you can move the issue to nuxt/framework to track support.
from ofetch.
BTW regarding example, for images you can directly reference them as :src
(ie: parsing to blob is probably not necessary)
https://codesandbox.io/s/fetch-blob-error-forked-mh1fm?file=/app.vue
from ofetch.
BTW regarding example, for images you can directly reference them as
:src
(ie: parsing to blob is probably not necessary)https://codesandbox.io/s/fetch-blob-error-forked-mh1fm?file=/app.vue
I need it to be in blob to send it to another service. It is not to render the image in html
from ofetch.
@frbuceta Apart from Blob support in
ohmyfetch
, the issue you were experiencing is solved if you return a value frommap
.<template> <pre> {{ banners }} </pre> </template> <script setup> import _ from "lodash"; // eslint-disable-next-line const { data: banners, refresh: bannersFetcher } = await useAsyncData( "banners", async () => { const banners = await $fetch("/api/banners").then((data) => { return Promise.all( _.map(data, async (banner) => { // const blob = await $fetch.raw(banner.data).then((res) => res.blob()); const blob = await fetch(banner.data).then((r) => r.blob()); console.log(blob); + return blob; }) ); }); console.log(banners); + return banners; } ); </script>
I try to pass the Blob to File but it doesn't work either.
const { data: banners, refresh: bannersFetcher } = await useAsyncData(
"banners",
async () => {
const banners = await $fetch("/api/banners").then((data) => {
return Promise.all(
_.map(data, async (banner) => {
// const blob = await $fetch.raw(banner.data).then((res) => res.blob());
const blob = await fetch(banner.data).then((r) => r.blob());
console.log(blob);
return { ...banner, file: new File([blob], banner.name) };
})
);
});
console.log(banners);
return banners;
}
);
from ofetch.
Related Issues (20)
- How to customize triggering errors
- `undefined` responses when used with React Native HOT 5
- feat: retry for 202 status code HOT 1
- Support custom Abortcontroller with timeout HOT 1
- Support for superjson HOT 4
- support modify params when retry
- FETCH_KEEP_ALIVE not respected when using native fetch
- Custom hook support
- How about WebSocket? HOT 1
- default retry is not able to be aware
- In Nuxt2, $fetch in plugin does not work HOT 2
- Attempting to use Datadog RUM with Nuxt in plugin, but fetch is already aliased before RUM can overwrite it. HOT 4
- I want to provide a Chinese README file, is it feasible? HOT 1
- onRequestError should called only once when retry? HOT 1
- [Question] how to get request options from the aborted request after all retries are performed and failed ? HOT 1
- Add a timeout reason for a timeout AbortSignal
- ๐ How to send `FormData` with `File` in node environment? HOT 1
- onOkResponse interceptor HOT 4
- Add file response type or the response headers to blob HOT 5
- Unsupported Engine Error for Node 20 and azure/msale 1.18 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ofetch.