def generate_upload_url(self, key, content_type=None, content_md5=None, expires_in=constants.SECONDS_PER_DAY, max_bytes=5 << 20): """Generates a URL for a PUT request to allow a client to store the specified key directly to S3 from a browser or mobile client. 'max_bytes' limits the upload file size to prevent D.O.S. attacks. TODO(andy) max_bytes is not currently enforced, need to fix this. """ headers = {} set_if_not_none(headers, 'Content-Type', content_type) set_if_not_none(headers, 'Content-MD5', content_md5) return self._s3_conn.generate_url(expires_in, 'PUT', self._bucket_name, key, headers=headers or None)
def generate_url(self, key, method='GET', cache_control=None, expires_in=constants.SECONDS_PER_DAY, content_type=None): """Generates a URL that can be used retrieve the specified key. If 'cache_control' is given, it will result in a Cache-Control header being added to any S3 responses. The expires_in parameter specifies how long (in seconds) the URL is valid for. content-type forces the content-type of the downloaded file. eg: use text/plain for logs. """ response_headers = {} set_if_not_none(response_headers, 'response-cache-control', cache_control) set_if_not_none(response_headers, 'response-content-type', content_type) return self._s3_conn.generate_url(expires_in, method, self._bucket_name, key, response_headers=response_headers or None)