Exemple #1
0
def chunk_upload(auth_token, sample_name, identifier, chunk_number):
    auth_token = str(auth_token)
    sample_name = str(sample_name)
    identifier = str(identifier)
    file = File.query.filter_by(identifier=identifier).first()

    try:
        chunk_number = int(chunk_number)
    except ValueError:
        return return_message('Error: invalid chunk number', 400)

    filename = request.form.get('flowFilename', type=str)
    total_chunks = request.form.get('flowTotalChunks', type=int)
    current_chunk_size = request.form.get('flowCurrentChunkSize', type=int)
    input_chunk = request.files['file']

    if not all([filename, total_chunks, current_chunk_size]):
        return return_message('Error: missing parameter', 400)

    if not file or file.upload_status != 'ongoing':
        return return_message('Error: Chunk refused, file status not set to ongoing', 202)

    temp_dir = get_tempdir(auth_token, identifier)
    chunk_filename = get_chunk_filename(temp_dir, chunk_number)

    try:
        make_tempdir(temp_dir)
    except DirectoryCreationError:
        return return_message('Error: File directory could not be created', 500)

    try:
        input_chunk.save(chunk_filename)
        if os.path.getsize(chunk_filename) != current_chunk_size:
            raise InvalidFileSize
        # BAM test for integrity done here since only the prioritized last chunk is needed to determine corruption
        if chunk_number == total_chunks and file.file_type == 'BAM/SAM':
            validate_bam(chunk_filename)
    except TruncatedBam:
        remove_from_uploads(temp_dir)
        update_file_status(identifier, 'corrupt')
        return return_message('Error: Truncated BAM file', 415)
    except InvalidFileSize:
        os.remove(chunk_filename)
        return return_message('Error: Chunk size on disk does not match', 500)
    except:
        os.remove(chunk_filename)
        return return_message('Error: Chunk could not be saved', 500)

    return return_message('Success: Upload of chunk complete', 200)
Exemple #2
0
def chunk_info(auth_token, sample_name, identifier, chunk_number):
    auth_token = str(auth_token)
    sample_name = str(sample_name)
    identifier = str(identifier)
    try:
        chunk_number = int(chunk_number)
    except ValueError:
        return return_message('Error: invalid chunk number', 400)

    temp_dir = get_tempdir(auth_token, identifier)
    chunk_filename = get_chunk_filename(temp_dir, chunk_number)
    if os.path.isfile(chunk_filename):
        # Chunk transfer completed successfully on HTTP code 200 only
        return return_message('Chunk already transferred', 200)
    # Chunk transfer not complete, send chunk requires HTTP code 204 (or anything other than 200, 400s, 500, 501)
    return return_message('Chunk not yet transferred', 204)
Exemple #3
0
def cancel_upload(auth_token, sample_name, identifier):
    auth_token = str(auth_token)
    sample_name = str(sample_name)
    identifier = str(identifier)

    file_row = File.query.filter_by(identifier=identifier).first()

    if not file_row:
        return return_message('Error: Identifier does not exist', 404)

    if file_row.upload_status != 'complete':
        update_file_status(identifier, 'cancelled')
        remove_from_uploads(get_tempdir(auth_token, identifier))
        return return_message('Success: Cancel received', 200)

    return return_message('Error: Upload already complete', 400)