Large file loaded into memory
Review this Python file-upload handler.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1import hashlib
2
3def upload_to_s3(s3, bucket, key, path):
4 with open(path, "rb") as f:
5 data = f.read()
6 digest = hashlib.sha256(data).hexdigest()
7 s3.put_object(
8 Bucket=bucket,
9 Key=key,
10 Body=data,
11 Metadata={"sha256": digest},
12 )
13 return digest
14
15def handle_upload(s3, bucket, request):
16 for upload in request.files: # may be GB-sized video files
17 key = f"uploads/{upload.filename}"
18 upload_to_s3(s3, bucket, key, upload.tmp_path)
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.