def screenshot(request,val): if val == 1 : conn = S3Connection('##', '##') bucket = conn.get_bucket('lheston-bucket') k = Key(bucket) k.key = '//lab3' + request + '_toS3.png' driver = webdriver.PhantomJS() # or add to your PATH driver.set_window_size(1024, 768) # optional driver.get(request) driver.save_screenshot('tempfile.png') driver.quit file1 = open('tempfile.png', 'rb') os.remove('tempfile.png') k.set_contents_from_file(file1) driver.quit return str(request + '_toS3.png') elif val == 2: text = '/lab3' + request conn = S3Connection('##', '##') S3_BUCKET_NAME = 'lheston-bucket' bucket = Bucket(conn, S3_BUCKET_NAME) bucket = bucket.delete_key(text) #bucket.delete_key('/lab3/' + request.split(':')[1]) #k = Key(b) #k.name = k.get_key(text) #b.delete_key(k) #k.name = k.get_key(text) #b.delete_key(k) #b.delete_key('//lab3' + request.split(':')[1] + '_toS3.png') else: return str('incorrect input')
def upload_to_s3(fp, name): conn = _get_s3_connection() bucket = conn.create_bucket('muxlist') k = Key(bucket) k.key = name k.set_contents_from_file(fp) return 'http://muxlist.s3.amazonaws.com/%s' % name
def save_product_image_to_s3(self): if any([key == self.slug for key in BUCKET_LIST]): return k = Key(bucket) k.key = self.slug file_object = urllib2.urlopen(self.img) fp = StringIO.StringIO(file_object.read()) k.set_contents_from_file(fp)
def store_image(self, callback, image_id, request, body=None, filename=None, **kwargs): bucket = self._get_bucket() image = Key(bucket, image_id) image.set_contents_from_file(body) callback(image.generate_url(HOUR))
def upload_content(bucket=None, key_name=None, data_type=kUploadContentType.String, data=None) : bucket = get_bucket(bucket) bucketKey = Key(bucket) bucketKey.key = key_name try : if data_type == kUploadContentType.String : bucketKey.set_contents_from_string(data) elif data_type == kUploadContentType.File : bucketKey.set_contents_from_file(data) elif data_type == kUploadContentType.FileName(data) : bucketKey.set_contents_from_filename(data) elif data_type == kUploadContentType.Stream : bucketKey.set_contents_from_stream(data) return True except Exception, e : return False
def _upload_file_to_bucket(self, file_path, destination): file_name = os.path.basename(file_path) destination_path = os.path.join(destination, file_name) log_info("Uploading '%s' to s3 bucket '%s' to '%s'" % (file_path, self.bucket_name, destination)) file_obj = open(file_path) k = Key(self.bucket) k.key = destination_path # set meta data (has to be before setting content in # order for it to work) k.set_metadata("Content-Type", "application/x-compressed") k.set_contents_from_file(file_obj) log_info("Completed upload '%s' to s3 bucket '%s'!" % (file_path, self.bucket_name))
def _upload_file_to_bucket(self, file_path, destination): file_name = os.path.basename(file_path) destination_path = os.path.join(destination, file_name) log_info("Uploading '%s' to s3 bucket '%s' to '%s'" % (file_path, self.bucket_name, destination)) file_obj = open(file_path) k = Key(self.bucket) k.key = destination_path # set meta data (has to be before setting content in # order for it to work) k.set_metadata("Content-Type", "application/x-compressed") k.set_contents_from_file(file_obj) log_info("Completed upload '%s' to s3 bucket '%s'!" % (file_path, self.bucket_name))
def post(): data = request.form files = request.files # adds a modicum of security... code = data.get('code') if code != os.environ.get('SEKKRIT_CODE'): err = Response(response="{'error':'unauthorized'}", status=401, mimetype="application/json") return err f = files.get('image') b = conn.get_bucket(S3_BUCKET) k = Key(b) path = data.get('filename') k.key = path k.set_contents_from_file(f) k.set_acl("public-read") #update the list of URLs stored in redis get_latest() #return the file name because reasons return json.dumps({"file" : path})
def store_image(self, callback, image_id, request, body=None, filename=None, **kwargs): bucket = self._get_bucket() image = Key(bucket, image_id) image.set_contents_from_file(body) callback(image.generate_url(HOUR))