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

Presigned URLs not generating properly. #80

Open
sikula opened this issue Apr 23, 2021 · 4 comments
Open

Presigned URLs not generating properly. #80

sikula opened this issue Apr 23, 2021 · 4 comments

Comments

@sikula
Copy link

sikula commented Apr 23, 2021

Environment

  • Elixir version (elixir -v):
    1.9.2

  • Waffle version (mix deps):
    1.1.3

  • Waffle dependencies when applicable (mix deps):
    waffle_ecto ~> 0.0.9
    ex_aws ~> 2.1.2
    ex_aws_s3 ~> 2.0

  • Operating system:
    Linux

Expected behavior

When I specify a custom filename

def filename(version, {file, scope}) do
  UUID.generate()
end

and generate a presigned url like so

Uploader.url({ MY_FILE_NAME })

The signed URL should be consistent

Actual behavior

The signed URL generates a new random UUID each time

Run 1:
Uploader.url({ MY_FILE_NAME }, signed: true)

%{
  original: "http://localhost:9000/images/uploads/[d7bce6fe-3180-414d-b502-d453f6ff9a59.jpeg?63786439354]?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20210423%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210423T232731Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=952864201db87b55f82b9cf1fab2ce1fa4915c90f62fd1fb5ca7430b54a0dd1f"
}

Run 2:
Uploader.url({ MY_FILE_NAME }, signed: true)

%{
  original: "http://localhost:9000/images/uploads/[c1734afe-0774-4e4e-b8f9-0a3859c08ae6.jpeg?63786439354]?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minio%2F20210423%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210423T232730Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=dd186a15e725b2f24e6a6398fc05d9f496020b4d2d493bf82852f5c035ab2cee"
}

Stuff in square brackets is to highlight the issue. Same filename, different URLs each time, this causes the storage to return "no such key" error.

@florius0
Copy link

Waffle does not support dynamic file naming.
So basically when you are trying to get file back, it just call filename/2

I'm struggling with this issue now to, as I want to have multiple files in one schema, but files that have same names will be rewritten on upload

@sikula
Copy link
Author

sikula commented Apr 25, 2021

Well that seems like a massive oversight because that makes presigned URLs practically impossible to use.

@achempion
Copy link
Member

yeah, seems like an issue we could improve upon

@achempion
Copy link
Member

btw, you can use "scope", to extract the current filename if it's exists, this should work for your case

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

3 participants