(session, log, batch_id, member, project, request)
| 79 | |
| 80 | |
| 81 | def append_to_batch_core(session, log, batch_id, member, project, request): |
| 82 | result = None |
| 83 | batch = InputBatch.get_by_id(session = session, id = batch_id) |
| 84 | |
| 85 | if batch.project_id != project.id: |
| 86 | log['error']['batch_id'] = "Batch is not from the provided project." |
| 87 | return False, log |
| 88 | |
| 89 | binary_file = request.files.get('file') |
| 90 | if not binary_file: |
| 91 | log['error']['binary_file'] = "No file provided" |
| 92 | return False, log |
| 93 | |
| 94 | file = request.files['file'] |
| 95 | # secure_filename makes sure the filename isn't unsafe to save |
| 96 | content_range = request.headers.get('Content-Range') |
| 97 | content_range_index = int(request.headers.get('Content-Range-Index')) |
| 98 | total_chunks = int(request.headers.get('Content-Range-Total-Chunks')) |
| 99 | if content_range.startswith('bytes'): |
| 100 | new_range = content_range.replace('bytes ', '') |
| 101 | chunks = new_range.split('/')[0] |
| 102 | size = int(new_range.split('/')[1]) |
| 103 | chunk_start = int(new_range.split('-')[0]) |
| 104 | chunk_end = int(chunks.split('-')[1]) |
| 105 | temp_dir_path = f'/tmp/batches/{batch.id}_batch_payload.json' |
| 106 | if chunk_start == 0: |
| 107 | session.add(batch) |
| 108 | url = data_tools.create_resumable_upload_session( |
| 109 | blob_path = temp_dir_path, |
| 110 | content_type = 'application/json', |
| 111 | input = None, |
| 112 | batch = batch |
| 113 | ) |
| 114 | batch.data_temp_dir = url |
| 115 | session.add(batch) |
| 116 | stream = file.stream.read() |
| 117 | content_size = len(stream) |
| 118 | |
| 119 | response = data_tools.transmit_chunk_of_resumable_upload( |
| 120 | stream = stream, |
| 121 | blob_path = temp_dir_path, |
| 122 | content_type = 'application/json', |
| 123 | prior_created_url = batch.data_temp_dir, |
| 124 | content_start = chunk_start, |
| 125 | content_size = content_size, |
| 126 | total_size = size, |
| 127 | total_parts_count = total_chunks, |
| 128 | chunk_index = content_range_index, |
| 129 | input = None, |
| 130 | batch = batch, |
| 131 | ) |
| 132 | else: |
| 133 | stream = file.stream.read() |
| 134 | content_size = len(stream) |
| 135 | |
| 136 | response = data_tools.transmit_chunk_of_resumable_upload( |
| 137 | stream = stream, |
| 138 | blob_path = temp_dir_path, |
no test coverage detected