diff --git a/scw/custom_types.go b/scw/custom_types.go index 5c8ed35bd..a7aa53e68 100644 --- a/scw/custom_types.go +++ b/scw/custom_types.go @@ -1,9 +1,11 @@ package scw import ( + "encoding/base64" "encoding/json" "fmt" "io" + "strings" "time" "github.com/scaleway/scaleway-sdk-go/internal/errors" @@ -37,6 +39,30 @@ type File struct { Content io.Reader `json:"content"` } +func (f *File) UnmarshalJSON(b []byte) error { + var tmpFile struct { + Name string `json:"name"` + ContentType string `json:"content_type"` + Content []byte `json:"content"` + } + + err := json.Unmarshal(b, &tmpFile) + if err != nil { + return err + } + + f.Name = tmpFile.Name + f.ContentType = tmpFile.ContentType + + content, err := base64.StdEncoding.DecodeString(string(tmpFile.Content)) + if err != nil { + return err + } + f.Content = strings.NewReader(string(content)) + + return nil +} + // Money represents an amount of money with its currency type. type Money struct { // CurrencyCode is the 3-letter currency code defined in ISO 4217.