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

BUG: Couldn't upload files to S3. Open an issue on Github and contact the repo owner. #88

Closed
nelsonic opened this issue Jul 6, 2023 · 2 comments · Fixed by #95
Closed
Assignees
Labels
BLOCKED :fire: Core team's HIGHEST priority, blocking critical work bug Suspected or confirmed bug (defect) in the code chore a tedious but necessary task often paying technical debt elixir Pull requests that update Elixir code T1h Time Estimate 1 Hour tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Jul 6, 2023

Getting the following error when attempting to upload on: https://imgup.fly.dev/liveview

Couldn't upload files to S3. Open an issue on Github and contact the repo owner.
image

@LuchoTurtle can you please investigate why if/when you have time? Thanks. 🙏

Note: this is almost certainly related to the work done for the "Edge Cases" PR: #86 / #69
The tests all pass on that branch so either the LiveView upload is insufficiently tested or the tests are a false positive. 💭

@nelsonic nelsonic added bug Suspected or confirmed bug (defect) in the code chore a tedious but necessary task often paying technical debt T1h Time Estimate 1 Hour technical A technical issue that requires understanding of the code, infrastructure or dependencies tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written elixir Pull requests that update Elixir code BLOCKED :fire: Core team's HIGHEST priority, blocking critical work labels Jul 6, 2023
@LuchoTurtle LuchoTurtle self-assigned this Jul 10, 2023
@LuchoTurtle
Copy link
Member

LuchoTurtle commented Jul 10, 2023

I don't believe this error was introduced because of the changes made in #86. Deployment only occurs when pushed to the main branch and the PR is still open.

The tests do pass on the branch but this error is highly likely an issue with environment variables not being properly set on either during the deployment phase or on Phoenix (maybe using get_env/2 is related to this problem).
The tests assume (and inclusively only succeed) if the env variables are properly set, which is the case when Phoenix runs in the test environment. Our issue is highly likely a faulty production environment, which is something that isn't meant to be tested in unit tests, so even if there are "false positives", it's not related to this.

I'll take a look into this. Because you've changed the env variables of the bucket names, I'm temporarily using both variants to discard this possibility.

image

In fact, the error that occurs (image below)...

image

indicates that the URL is not being formed correctly. Instead of being {bucket}.s3-eu-west-3, it's returning .s3-eu-west-3, which is an invalid URL, meaning it's a problem with env variables.

defp presign_upload(entry, socket) do
uploads = socket.assigns.uploads
bucket_original = Application.get_env(:ex_aws, :original_bucket)
bucket_compressed = Application.get_env(:ex_aws, :compressed_bucket)
key = Cid.cid("#{DateTime.utc_now() |> DateTime.to_iso8601()}_#{entry.client_name}")
config = %{
region: System.get_env("AWS_REGION"),
access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY")
}
{:ok, fields} =
SimpleS3Upload.sign_form_upload(config, bucket_original,
key: key,
content_type: entry.client_type,
max_file_size: uploads[entry.upload_config].max_file_size,
expires_in: :timer.hours(1)
)
meta = %{
uploader: "S3",
key: key,
url: "https://#{bucket_original}.s3-#{config.region}.amazonaws.com",
compressed_url: "https://#{bucket_compressed}.s3-#{config.region}.amazonaws.com",
fields: fields
}
{:ok, meta, socket}
end

@nelsonic
Copy link
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BLOCKED :fire: Core team's HIGHEST priority, blocking critical work bug Suspected or confirmed bug (defect) in the code chore a tedious but necessary task often paying technical debt elixir Pull requests that update Elixir code T1h Time Estimate 1 Hour tech-debt A feature/requirement implemented in a sub-optimal way & must be re-written technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants