سؤال

Is there a way to create a Key for a connection without validation using boto? The docs say there is a validate parameter, but it doesn't exist in the 2.23 source (which is supposedly the same version as the docs).

I need a workaround to avoid doing the lookup on the key.

هل كانت مفيدة؟

المحلول

The get_key() method in boto.s3.bucket.Bucket performs a HEAD request on the object to verify that it exists. If you are sure the object exists and don't want the overhead of the HEAD request, simply create the Key object directly like this:

import boto.s3
from boto.s3.key import Key

conn = boto.s3.connect_to_region('us-east-1')
bucket = conn.get_bucket('mybucket', validate=False)
key = Key(bucket, 'mykeyname')

This avoids the HEAD request and still allows you to perform normal operations on the Key object. Note, however, that the HEAD request retrieves certain metadata about the Key in question such as its content-type, size, ETag, etc. The Key object constructed directly will not have that information available.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top