aws-beam/aws-elixir

AWS.S3.get_object automatically decodes body as xml

berendeanicolae opened this issue · 2 comments

I'm trying to download a file from S3 using AWS.S3.get_object(client, bucket, path) but the function fails with the error

** (FunctionClauseError) no function clause matching in :lists.prefix/2    
   
    The following arguments were given to :lists.prefix/2:
   
        # 1
        '<'
   
        # 2
        {:error, [],
         <<137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 9, 225,
           0, 0, 6, 156, 8, 6, 0, 0, 0, 145, 146, 199, 218, 0, 0, 12, 23, 105, 67, 67,
           80, 73, 67, 67, 32, 80, 114, ...>>}
   
    (stdlib 3.13) lists.erl:192: :lists.prefix/2
    (xmerl 1.3.25) xmerl_scan.erl:3910: :xmerl_scan.scan_mandatory/5
    (xmerl 1.3.25) xmerl_scan.erl:572: :xmerl_scan.scan_document/2
    (xmerl 1.3.25) xmerl_scan.erl:291: :xmerl_scan.string/2
    (aws 0.7.0) lib/aws/xml.ex:42: AWS.XML.decode!/2
    (aws 0.7.0) lib/aws/request.ex:104: AWS.Request.request_rest/9

From what I see, the S3 module uses rest-xml as default protocol [1] which causes the response to be interpreted as a xml and decoded [2].
Is this the right way to download files or another function should be used?

[1] https://github.com/aws-beam/aws-elixir/blob/master/lib/aws/generated/s3.ex#L16
[2] https://github.com/aws-beam/aws-elixir/blob/master/lib/aws/request.ex#L104

Hi @berendeanicolae I found exactly the same while using the Erlang client. This has been fixed (yesterday) for the Erlang part, but it still needs to be applied to the Elixir side. An issue already exists for it: aws-beam/aws-codegen#71

Hi @berendeanicolae! 👋
The problem is fixed on master (see #61). Thanks for opening the issue 💜