agraboso / agraboso/redux-api-middleware

[2.0.0] Handling a ReadableStream in response

Abierto
#146 1 comentario 0 reacciones 0 asignados Ver en GitHub
question
Lenguaje dominante
JavaScript
Estrellas
1.5k
Forks
190
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

```
export const fetchImage = imageName => ({
[CALL_API]: {
endpoint: `/resources/${imageName}.jpg`,
method: 'GET',
types: [
IMAGE_REQUEST,
{
type: IMAGE_SUCCESS,
meta: { imageName },
payload: (action, state, res) => res.arrayBuffer()
},
IMAGE_FAILED],
},
});
```
Im trying to retrieve an image as an arraybuffer (it is protected with a jwt token so I need to fetch it myself and add the raw data to the ).
But the readable stream returns a Promise (res.arraybuffer() https://jakearchibald.com/2015/thats-so-fetch/) and I'm stuck on how to handle that further down the road.

I tried

```
case IMAGE_SUCCESS: {
const mimetype = 'image/jpg';
const arrayBufferPromise = action.payload;
const imageName = action.meta.imageName;

return {
...state,
[imageName]: arrayBufferPromise.then(arrayBuffer => encodeImage(arrayBuffer, mimetype)),
loading: false,
};
}
```
but without success.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.