Esempio n. 1
0
def upload_audio(message_id):
    try:
        file = request.files['file']
        if file and is_extension_allowed(file.filename, 'audio'):
            target_filename = message_id + '.' + file.filename.rsplit('.',
                                                                      1)[1]
            import os
            path = os.path.realpath('.') + os.path.join(
                app.config['UPLOAD_FOLDER_AUDIO'], target_filename)
            print path
            file.save(path)

            if str(message_id)[0] == 'g':
                m = models.GroupChatMessage.query.get(message_id[1::])
            else:
                m = models.ChatMessage.query.get(message_id)
            m.audio_content = target_filename
            db.session.commit()
            return response.response_ok('Upload file successful')
        else:
            return response.response_fail(
                'Error uploading file: file type not allowed')
    except Exception as e:
        print e
        return response.response_fail('Error uploading file %s' % e)
Esempio n. 2
0
def upload_pic(status_id, index):
    try:
        file = request.files['file']
        if file and is_extension_allowed(file.filename, 'pic'):
            target_filename = status_id + '_' + index + '.' + file.filename.rsplit('.', 1)[1]
            import os
            path = os.path.realpath('.') + os.path.join(app.config['UPLOAD_FOLDER_PIC'], target_filename)
            file.save(path)
            p = models.Picture(content=target_filename, status_id=status_id)
            db.session.add(p)
            db.session.commit()
            return response.response_ok('Upload file successful')
        else:
            return response.response_fail('Error uploading file: file type not allowed')
    except Exception as e:
        return response.response_fail('Error uploading file %s' % e)
Esempio n. 3
0
def upload_pic(status_id, index):
    try:
        file = request.files['file']
        if file and is_extension_allowed(file.filename, 'pic'):
            target_filename = status_id + '_' + index + '.' + file.filename.rsplit(
                '.', 1)[1]
            import os
            path = os.path.realpath('.') + os.path.join(
                app.config['UPLOAD_FOLDER_PIC'], target_filename)
            file.save(path)
            p = models.Picture(content=target_filename, status_id=status_id)
            db.session.add(p)
            db.session.commit()
            return response.response_ok('Upload file successful')
        else:
            return response.response_fail(
                'Error uploading file: file type not allowed')
    except Exception as e:
        return response.response_fail('Error uploading file %s' % e)
Esempio n. 4
0
def upload_audio(message_id):
    try:
        file = request.files['file']
        if file and is_extension_allowed(file.filename, 'audio'):
            target_filename = message_id + '.' + file.filename.rsplit('.', 1)[1]
            import os
            path = os.path.realpath('.') + os.path.join(app.config['UPLOAD_FOLDER_AUDIO'], target_filename)
            print path
            file.save(path)

            if str(message_id)[0] == 'g':
                m = models.GroupChatMessage.query.get(message_id[1::])
            else:
                m = models.ChatMessage.query.get(message_id)
            m.audio_content = target_filename
            db.session.commit()
            return response.response_ok('Upload file successful')
        else:
            return response.response_fail('Error uploading file: file type not allowed')
    except Exception as e:
        print e
        return response.response_fail('Error uploading file %s' % e)