Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc ecto image fetch from aws s3 #31

Closed
ghost opened this issue Jun 14, 2016 · 2 comments
Closed

Arc ecto image fetch from aws s3 #31

ghost opened this issue Jun 14, 2016 · 2 comments

Comments

@ghost
Copy link

ghost commented Jun 14, 2016

I am not sure whether this is a arc or arc_ecto or ex_aws issue, when I upload the image that works fine I guess, at least there are no errors. now while fetching the image like this MyApp.Avatar.url({ user.photo, user}, :thumb, signed: true)

it throws this error:

<Error>
  <Code>SignatureDoesNotMatch</Code>
  <Message>
    The request signature we calculated does not match the signature you provided. Check your key and signing method.
  </Message>
  <AWSAccessKeyId>ACCESSID</AWSAccessKeyId>
  <StringToSign>
    AWS4-HMAC-SHA256 20160613T132235Z 20160613/us-east-1/s3/aws4_request 3119114
  </StringToSign>
  <SignatureProvided>
    f1e2764695
  </SignatureProvided>
  <StringToSignBytes>
     stuff
  </StringToSignBytes>
  <CanonicalRequest>
    GET /memento-is-dev/uploads/Screenshot%20from%202016-05-24%2014%3A43%3A13.png X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ACCESS%2F20160613%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20160613T131355Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&v=63633027268 host:s3.amazonaws.com host UNSIGNED-PAYLOAD
  </CanonicalRequest>
  <CanonicalRequestBytes>
    stuff
  </CanonicalRequestBytes>
  <HostId>
    fjO3c4Y=
  </HostId>
</Error>

I am using ecto 1.x with arc_ecto 0.3.2 and arc 0.5

here is some code in the controller to insert an image:

    case Repo.insert(changeset) do
      {:ok, prof} ->
        IO.inspect prof
        Expense.Avatar.store({transaction_params["image"], prof})

        conn
        |> put_flash(:info, "Profile created successfully")
        |> redirect(to: user_profile_path(conn, :index, user_id))
      {:error, changeset} ->
        render(conn, "index.html", changeset: changeset)
    end
@tiagoengel
Copy link

tiagoengel commented Jun 14, 2016

I'm getting this problem too, this is because of the v (version) query parameter that is added to the url. According to the aws documentation every query parameter and header should be used to calculate the signature.

I don't really see the point of adding this parameter for signed urls, I think it could be removed when the option signed is true. If there's a reason to keep it, it should be passed along to ex_aws in some way.

As a workaround I'm manually removing this parameter from the url for now

urls_with_version = ProjectImage.urls({image, project}, signed: true)

Enum.reduce(urls_with_version, %{}, fn ({key, value}, acc) ->
  Map.put(acc, key, String.replace(value, ~r/&v=(.*)$/, ""))
end)

@stavro stavro closed this as completed in 47508ab Jun 14, 2016
@stavro
Copy link
Owner

stavro commented Jun 14, 2016

Thanks for investigating!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants