Ejemplo n.º 1
0
    def _process_image_field(self, field, imagetype, thumbnails):
        filepath = lambda name, label: self.Meta.model.get_image_filepath(
            self.account_id, name, imagetype, label)

        if isinstance(field.data, basestring):
            field.data = field.data.rsplit('/')[-1]
            original_path = filepath(field.data, 'original')
            if not media_bucket.get_key(original_path):
                raise wtforms.ValidationError('%s not found.' % original_path)
        else:
            try:
                image = Image.open(field.data)
                content_type = Image.MIME[image.format]
            except Exception as e:
                raise wtforms.ValidationError(e.message)

            stream = field.data.stream
            stream.seek(0)

            field.data = get_random_filename()
            upload_file(media_bucket, filepath(field.data, 'original'),
                        stream, content_type)

            if thumbnails is True:
                thumbnails = '%s_THUMBNAIL_SIZES' % imagetype.upper()
            if isinstance(thumbnails, basestring):
                thumbnails = current_app.config[thumbnails]
            for size, buf in resize(image, thumbnails, save_to_buffer='jpeg'):
                upload_file(media_bucket, filepath(field.data, str(size[0])),
                            buf, 'image/jpeg')

        return field
Ejemplo n.º 2
0
 def get(self, account, dollyuser):
     filetype = request.args.get('type')
     if filetype in ('profile_cover', 'avatar'):
         get_filepath = partial(current_user.get_image_filepath, imagetype=filetype)
         bucket = media_bucket.name
     else:
         get_filepath = Video.get_video_filepath
         bucket = video_bucket.name
     key = get_filepath(account.id, get_random_filename())
     args = s3connection.build_post_form_args(bucket, key, 3600, storage_class=None)
     # Force https on top-level s3 domain to avoid browser security warnings
     args['action'] = 'https://%s/%s/' % (s3connection.server_name(), video_bucket.name)
     return args
Ejemplo n.º 3
0
def migrate_video_files(account):
    for video in Video.query.filter_by(account_id=account, filename='dolly'):
        metadata = ooyala.ooyala_request('assets', video.external_id, 'metadata')
        key = video_bucket.get_key(metadata['path'])
        assert key.size < 5 * 2 ** 30   # can't copy files bigger than this

        video.filename = get_random_filename()
        dst = Video.get_video_filepath(account, video.filename)
        key.copy(video_bucket.name, dst)
        key.delete()

        ooyala.set_metadata(video.external_id, dict(path=dst, label=account))

    db.session.commit()