""" Handles file operations (local and remote) """ import boto from boto.s3.key import Key from bulkperformancerights import config def put_to_s3(file, user_path): """PUT local file to AWS s3 Args: file (file): file handle user_path (string): path on s3 for user Return: (int): The number of bytes written to the key. """ s3 = boto.connect_s3() bucket = s3.get_bucket(config.bucket_name) # make bucket_name a function k = Key(bucket) k.key = config.prefix + user_path + file.filename return k.set_contents_from_file(file) def allowed_file(filename): """Check the file extension Args: filename (string): filename Todo: (OrCharles) actually check the content_type, in another method Return: bool """ return '.' in filename and \ filename.rsplit('.', 1)[1] in config.ALLOWED_EXTENSIONS