当前位置: 首页>>代码示例>>Python>>正文


Python Key.content_type方法代码示例

本文整理汇总了Python中boto.s3.connection.Key.content_type方法的典型用法代码示例。如果您正苦于以下问题:Python Key.content_type方法的具体用法?Python Key.content_type怎么用?Python Key.content_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.s3.connection.Key的用法示例。


在下文中一共展示了Key.content_type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import content_type [as 别名]
    def upload(self):
        for destination, data, content_type, compressed in self.get_files():
            key = Key(self.bucket)
            key.content_type = content_type
            if compressed:
                key.set_metadata('content-encoding', 'gzip')

            for header, value in self.headers:
                key.set_metadata(header, value)
            key.key = destination
            key.set_contents_from_string(data)
开发者ID:cknv,项目名称:beetle-s3uploader,代码行数:13,代码来源:__init__.py

示例2: createVideo

# 需要导入模块: from boto.s3.connection import Key [as 别名]
# 或者: from boto.s3.connection.Key import content_type [as 别名]
    def createVideo():
        req = flask.request.get_json()['params']
        session = database.DBSession()

        # Check if the user is allowed to access this method
        allowed = authorized.authorized(req['user_id'], req['access_token'], session)
        if allowed is not True:
            session.close()
            return allowed

        from user import Connection

        # Create the video and send back a response
        video_date = int(req['date'])
        user_id = req['user_id']
        timeline_id = req['timeline_id']
        if timeline_id == '':
            timeline_id = string_constants.kServerVideoPublicFeedKey
        description = req['description']
        public_feed = False
        if 'public_feed' in req:
            public_feed = bool(req['public_feed'])

        video_content = None
        if 'video_content' in req:
            video_content = base64.b64decode(req['video_content'])

        video_thumbnail = None
        if 'video_thumbnail' in req:
            video_thumbnail = base64.b64decode(req['video_thumbnail'])

        if video_date is None or user_id is None or timeline_id is None or description is None:
            session.close()
            return authorized.wrongParams()

        # Add video_id to the playlist in the relationship
        timeline = None
        if timeline_id != string_constants.kServerVideoPublicFeedKey:
            timeline = session.query(Timeline).filter(Timeline.timeline_id == timeline_id).join(Timeline.connection).filter(Connection.approved == 1).filter(Connection.disabled == 0).first()
            if timeline is None:
                response = jsonify(message=string_constants.kServerVideoTimelineIDDoesntExist,
                                   status=False,
                                   HTTP_CODE=200
                )
                response.status_code = 200
                session.close()
                return response

        video_filename = hashlib.sha256(str(video_date) + user_id + timeline_id).hexdigest()

        # Check if video already exists
        video_check = session.query(VideoModel).filter(VideoModel.video_id == video_filename).first()
        if video_check is not None:
            response = jsonify(message=string_constants.kServerVideoAlreadyExistsError,
                               status=False,
                               HTTP_CODE=200
            )
            response.status_code = 200
            session.close()
            return response

        try:

            video_path = str(Video.getVideoObjectPath(video_filename, user_id, timeline_id, str(video_date))+".m4v")
            thumbnail_path = str(Video.getVideoThumbnailObjectPath(video_filename, user_id, timeline_id, str(video_date))+".jpg")

            if app.config["AWS_S3"]:
                if video_content is not None and video_thumbnail is not None:
                    aws_s3_connection = S3Connection(app.config['AWS_ACCESS_KEY'], app.config['AWS_SECRET_KEY'])
                    aws_s3_bucket = Bucket(aws_s3_connection, app.config['AWS_BUCKET_NAME'])
                    aws_s3_video_key = Key(aws_s3_bucket)
                    aws_s3_video_key.key = video_path
                    aws_s3_video_key.content_type = app.config['AWS_KEY_CONTENT_TYPE']
                    aws_s3_video_key.set_contents_from_string(video_content, replace=True)
                    aws_s3_thumb_key = Key(aws_s3_bucket)
                    aws_s3_thumb_key.key = thumbnail_path
                    aws_s3_thumb_key.content_type = app.config['AWS_KEY_CONTENT_TYPE']
                    aws_s3_thumb_key.set_contents_from_string(video_thumbnail, replace=True)

            # Create new video object and save it to the database
            new_video = VideoModel(video_date, user_id, timeline_id, video_filename + '_thumb.jpg', video_filename, description, public_feed)
            if timeline is not None:
                timeline.video_count += 1

                from user import UserModel

                userDisplayName = session.query(UserModel.display_name).filter(UserModel.user_id == int(user_id)).first()
                userDisplayName = userDisplayName[0]

                # Add the notification for the new video
                from notification import NotificationModel, RegisteredNotificationUserModel

                notification = NotificationModel(
                    user_id,
                    (int(timeline.connection.user1) == int(user_id)) and timeline.connection.user2 or timeline.connection.user1, {
                        string_constants.kServerNotificationsType: string_constants.kServerNotificationsTypeNewVideo,
                        string_constants.kServerNotificationsTimeline_idKey: timeline_id,
                        string_constants.kServerNotificationsUser_NameKey: userDisplayName
                    }, calendar.timegm(datetime.utcnow().timetuple()))
                session.add(notification)
#.........这里部分代码省略.........
开发者ID:andrewapperley,项目名称:Blips-Server,代码行数:103,代码来源:video.py


注:本文中的boto.s3.connection.Key.content_type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。