예제 #1
0
파일: video.py 프로젝트: WillZhougz/leggy
def upload():
    if request.method == 'POST':
        file = request.files['file']

        if file:
            filename = secure_filename(file.filename)
            filename = util.video.get_non_conflict_name(filename, current_user)
            mimetype = file.content_type

            if not util.video.allowed_file(filename):
                result = util.video.UploadResponse(name=filename,
                                                   type=mimetype,
                                                   size=0,
                                                   not_allowed_msg="Filetype not allowed")

            else:
                # save then record to db
                video = Video.upload(file, filename, current_user)

                # create thumbnail after saving
                # if mimetype.startswith('image'):
                #     create_thumbnai(filename)

                # return json for js call back
                result = util.video.UploadResponse(name=video.title,
                                                   type=mimetype,
                                                   size=video.size,
                                                   not_allowed_msg=None,
                                                   url=url_for('video.play', id=video.id),
                                                   delete_url=url_for('video.delete', id=video.id))

            # for validation
            return simplejson.dumps({"files": [result.get_file()]})

    if request.method == 'GET':
        return get_current_videos()

    redirect(url_for('video.manage'))