fix: webserver: Catch and report IO errors on upload
Signed-off-by: Matthias Blankertz <matthias@blankertz.org>
This commit is contained in:
@@ -219,11 +219,17 @@ async def audiofile_upload(request):
|
||||
data = array('b', range(4096))
|
||||
bytes_copied = 0
|
||||
while True:
|
||||
try:
|
||||
bytes_read = await request.stream.readinto(data)
|
||||
except OSError as ex:
|
||||
return f'read error: {ex}', 500
|
||||
if bytes_read == 0:
|
||||
# End of body
|
||||
break
|
||||
try:
|
||||
bytes_written = newfile.write(data[:bytes_read])
|
||||
except OSError as ex:
|
||||
return f'write error: {ex}', 500
|
||||
if bytes_written != bytes_read:
|
||||
# short writes shouldn't happen
|
||||
return 'write failure', 500
|
||||
|
||||
Reference in New Issue
Block a user