(session,
log,
project_string_id,
http_input,
file,
directory_id,
parent_file_id=None,
ordinal = 0
)
| 329 | |
| 330 | |
| 331 | def input_from_local(session, |
| 332 | log, |
| 333 | project_string_id, |
| 334 | http_input, |
| 335 | file, |
| 336 | directory_id, |
| 337 | parent_file_id=None, |
| 338 | ordinal = 0 |
| 339 | ): |
| 340 | immediate_mode = True |
| 341 | |
| 342 | input = Input() |
| 343 | input.directory_id = directory_id |
| 344 | |
| 345 | if http_input['instance_list']: |
| 346 | input.instance_list = {} |
| 347 | input.instance_list['list'] = http_input['instance_list'] |
| 348 | |
| 349 | if http_input['frame_packet_map']: |
| 350 | input.frame_packet_map = http_input['frame_packet_map'] |
| 351 | |
| 352 | # only need to make temp dir if file doesn't already exist... |
| 353 | |
| 354 | original_filename = secure_filename(file.filename) # http://flask.pocoo.org/docs/0.12/patterns/fileuploads/ |
| 355 | |
| 356 | input.extension = os.path.splitext(original_filename)[1].lower() |
| 357 | input.original_filename = os.path.split(original_filename)[1] |
| 358 | input.parent_file_id = parent_file_id |
| 359 | input.ordinal = ordinal |
| 360 | |
| 361 | input.temp_dir = tempfile.mkdtemp() |
| 362 | input.temp_dir_path_and_filename = input.temp_dir + \ |
| 363 | "/" + original_filename + input.extension |
| 364 | |
| 365 | project = Project.get(session, project_string_id) |
| 366 | |
| 367 | input.project = project |
| 368 | |
| 369 | input.media_type = None |
| 370 | input.media_type = Process_Media.determine_media_type(input.extension) |
| 371 | if not input.media_type: |
| 372 | input.status = "failed" |
| 373 | input.status_text = f"Invalid file type: {input.extension}" |
| 374 | return False, log, input |
| 375 | |
| 376 | session.add(input) |
| 377 | session.flush() |
| 378 | |
| 379 | with open(input.temp_dir_path_and_filename, "wb") as f: |
| 380 | |
| 381 | f.write(file.stream.read()) |
| 382 | |
| 383 | # For LOCAL not normal upload |
| 384 | file_size_limit = 9 * 1024 * 1024 * 1024 |
| 385 | |
| 386 | file_size = os.path.getsize(input.temp_dir_path_and_filename) # gets size in bytes |
| 387 | |
| 388 | if file_size > file_size_limit: |
no test coverage detected