risor-io / risor

Fast and flexible scripting for Go developers and DevOps.
https://risor.io
Apache License 2.0
741 stars 31 forks source link

AWS S3 put_object results in a "cannot unmarshal string into Go struct" error #266

Open lmika opened 2 months ago

lmika commented 2 months ago

Hi,

I'm trying out the AWS S3 client for Risor, and I'm finding that putting an object using put_object would fail with the following error:

json: cannot unmarshal string into Go struct field PutObjectInput.Body of type io.Reader

Here's an sample script of what I'm trying to do:

s3 := aws.client("s3")

func upload_file_to_s3(file, key) {
  bts := os.read_file(file)

  s3.put_object({
    Bucket: "my-bucket",
    Key: key,
    Body: bts,
  })
}

upload_file_to_s3("my-file.txt", "/object/path.txt")

Using os.open() in place of os.read_file would also produce the same error.

I'd imagine it may have something to with how the parameters are converted to the AWS types. These aren't large files so if you know of an alternative field to Body I can use instead, that would work for ne.

myzie commented 2 months ago

Thanks for reporting this. Haven’t had a chance to diagnose yet but will soon.

lmika commented 2 months ago

Hi @myzie , thanks for that. I did have a go at hacking a fix for this, which you can find here: https://github.com/lmika/risor/commit/517360907dcaf26e29b2a0472d16e626ec063760. I've been using it on my fork and it's been working for me (granted, I haven't done a lot of testing of it). I'll be happy to clean it up and raise it as a MR if you're interested.