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

Creating an S3 signed URL without downloading the object #836

Closed
benbc opened this issue Apr 4, 2012 · 7 comments
Closed

Creating an S3 signed URL without downloading the object #836

benbc opened this issue Apr 4, 2012 · 7 comments

Comments

@benbc
Copy link
Contributor

benbc commented Apr 4, 2012

I'm using fog to generate signed URLs for S3, like this:

s3.directories.get(BUCKET).files.get(object).url(expiry)

This causes fog to download the entire object, which I don't need to do.

Is there any way to create the signed URL without downloading the object?

@benmanns
Copy link
Member

benmanns commented Apr 4, 2012

You can use head to avoid downloading the whole object (this does a HEAD request, which pulls headers but not the file content). If you don't care about pulling headers or checking that the object exists, you can use new to build a file object, which you can use to create a URL without any requests S3.

Using head to validate object existence:

s3.directories.get(BUCKET).files.head(object).url(expiry)

Without touching S3:

s3.directories.new(:key => BUCKET).files.new(:key => object).url(expiry)

@benmanns benmanns closed this as completed Apr 4, 2012
@benbc
Copy link
Contributor Author

benbc commented Apr 4, 2012

Wonderful. Thank you.

@geemus
Copy link
Member

geemus commented Apr 4, 2012

@benmanns thanks for covering this, spot on info.

@will
Copy link
Contributor

will commented Nov 15, 2012

Woah, thanks to mark fine for linking this issue. My app was surprise downloading huge things just to make a url, I had no idea.

@geemus
Copy link
Member

geemus commented Nov 15, 2012

@will - fwiw, there is another way which avoids the head request also (if you can reasonably assume that the file exists). Happy to discuss or help out with any S3 stuff you might have going on, I have used it a lot, probably too much.

@tischler
Copy link

@geemus this page comes up fairly easy when googling for signed URLs. if you know a better way, you should add a link to this thread... cheers!

@geemus
Copy link
Member

geemus commented May 1, 2015

Hmm, hard to remember now. I think basically you can just do the second part above (with new calls), but skip the head step. If the file doesn't really exist it would be invalid, but if you have reason to believe it does, it saves you the round-trip. I think that is probably what I meant, but, has been a while. Hope that helps!

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

5 participants