I'm pretty new to elm and stuck with a problem regarding populating my model with data from my backend. I'm curently able to make a get request to the server which returns a byte[] (the data is any kind of image,audio or video), which works fine when just displaying this data by for example Html.img. When I try to use Http.get (src: https://package.elm-lang.org/packages/elm/http/latest/Http) to populate my model it requires a decoder. The problem is, that Bytes.Decode.bytes requires an Int to know how many bytes have to be decoded. So my question is: Is there any way to access the byte width while still matching the type pattern of Http.get?
Here's a simple example of my problem:
import Bytes exposing (Bytes)
import Bytes.Decode exposing (Decoder, bytes, decode)
import GeneralTypes exposing (Msg(..))
import Http
getMediaFromUrl : Cmd Msg
getMediaFromUrl = Http.get
{ url = "http://localhost:8090/image/2006/aa@a.de/session"
, expect = Http.expectBytes GetThumbnail decodeBytes
}
decodeBytes: Bytes.Bytes -> Decoder Bytes
decodeBytes bytesToDecode= let
fileSize =
bytesToDecode |> Bytes.width
in
Bytes.Decode.bytes fileSize
module GeneralTypes exposing (..)
import Bytes exposing (Bytes)
import Http
type Msg = GetThumbnail (Result Http.Error Bytes)