Esempio n. 1
0
def upload_change_obj():
    if request.method == 'POST':
        response = UserModel.get_user_from_session(
            request.headers.get('SessionId'))
        if response['Status'] == 200:
            submitted_file = request.files['file']
            file_obj = FileModel(submitted_file)
            file_valid_response = file_obj.check_file_extension()
            if file_valid_response['Status'] == 200:
                file_obj.upload_file_landing()
                file_path = file_obj.upload_file_s3()
                file_obj.delete_file_landing()
                if file_path is not None:
                    response = {
                        'Status': 201,
                        'Filepath': file_path,
                        'Message': 'Successfully uploaded'
                    }
                else:
                    response = {
                        'Status': 201,
                        'FileName': file_obj.file_name,
                        'Message': 'Could not upload file'
                    }
        return json.dumps(response)
Esempio n. 2
0
def upload_files():
    if request.method == 'POST':
        response = UserModel.get_user_from_session(
            request.headers.get('SessionId'))
        if response['Status'] == 200:
            submitted_files = request.files
            dataset_id = generate_unique_identifier()
            response = {'Status': 201, 'DataSetId': dataset_id, 'Files': []}
            for file in submitted_files.keys():
                file_id = generate_unique_identifier()
                file_obj = FileModel(submitted_files[file])
                file_valid_response = file_obj.check_file_extension()
                if file_valid_response['Status'] == 200:
                    file_obj.upload_file_landing()
                    file_path = file_obj.upload_dataset_file_s3(
                        dataset_id, file_id)
                    if file_path is not None:
                        file_obj.delete_file_landing()
                        response['Files'].append({
                            'FileId':
                            file_id,
                            'FileName':
                            file_obj.file_name,
                            'Message':
                            'Successfully uploaded'
                        })
                    else:
                        response['Files'].append({
                            'FileId':
                            file_id,
                            'FileName':
                            file_obj.file_name,
                            'Message':
                            'Could not upload to S3'
                        })
                else:
                    response['Files'].append({
                        'Status':
                        file_valid_response['Status'],
                        'FileId':
                        file_id,
                        'Message':
                        file_valid_response['Message']
                    })
            return json.dumps(response)
        else:
            return response