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

Amazon and redirects #3

Closed
tmikaeld opened this issue Feb 12, 2022 · 4 comments
Closed

Amazon and redirects #3

tmikaeld opened this issue Feb 12, 2022 · 4 comments

Comments

@tmikaeld
Copy link

tmikaeld commented Feb 12, 2022

When I used an EU region for Amazon, it did a 301 redirect response which was followed automatically in Deno but since you only accept 200 response, I'm not sure if it should be a setting or not?

@bradenmacdonald
Copy link
Owner

Can you give me some more details? Which method are you using - getObject ? Is this an authenticated or unauthenticated request? What configuration of the bucket is resulting in a redirect? (this?) Is it redirecting to another key in the same bucket, or to an external URL?

I think it's a little involved to handle this situation, as if it's an external URL it doesn't make sense to treat it as an Amazon request. But if it's redirecting to another key on the same bucket, a whole new request has to be generated and signed; presumably simply getting the new URL won't work without authentication.

@tmikaeld
Copy link
Author

tmikaeld commented Feb 13, 2022

Sorry, I should have sent an example from the start.

import { S3Client } from "https://deno.land/x/[email protected]/mod.ts";

// Connecting to a local MinIO server:
const s3client = new S3Client({
  endPoint: "s3.amazonaws.com",
  region: "eu-central-1",
  accessKey: "secret",
  secretKey: "Secret",
  bucket: "test",
  pathStyle: true,
});

await s3client.getObject("test.txt");

Gives:

error: Uncaught (in promise) Error: Unexpected response code from the server (expected 200, got 301 Moved Permanently).
        throw new errors.ServerError(
              ^
    at Client.makeRequest (https://deno.land/x/[email protected]/client.ts:270:15)
    at async Client.getPartialObject (https://deno.land/x/[email protected]/client.ts:388:12)
    at async file:///home/tests/server.ts:14:1

The redirect URL is just the same URL, so not sure why it's even replying with 301...

@bradenmacdonald
Copy link
Owner

Ah @tmikaeld I see now. I believe you just need to change the endPoint setting to s3.eu-central-1.amazonaws.com and then it won't be redirecting you.

@tmikaeld
Copy link
Author

You are correct sir, now it works! Thanks 👍

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