You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upload handler created with unstable_createFileUploadHandler leaves incomplete files on disk if the request is aborted. Because the filename may not be known until the Promise from unstable_parseMultipartFormData resolves, it is impossible to delete the file in action if the ECONNRESET error is caught.
The handler is already able to remove some failed uploads (when the allowed size is exceeded, see the fragment below) and could be modified to set deleteFile = true if any error occurs.
My idea is to add a catch block before finally, set deleteFile and rethrow. The finally will still be executed, clean up and the error will be rethrown to handle up in the stack.
Special handling for ECONNRESET
try{// ... (no change)}catch(error){if((errorasany).code==="ECONNRESET"){deleteFile=true;}throwerror;}finally{// ... (no change)}
Delete file on any error
try{forawait(letchunkofdata){size+=chunk.byteLength;if(size>maxPartSize){// The `catch` block will set `deleteFile = true`, so it's not necessary herethrownewMaxPartSizeExceededError(name,maxPartSize);}writeFileStream.write(chunk);}}catch(error){deleteFile=true;throwerror;}finally{// ... (no change)}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Upload handler created with
unstable_createFileUploadHandler
leaves incomplete files on disk if the request is aborted. Because the filename may not be known until thePromise
fromunstable_parseMultipartFormData
resolves, it is impossible to delete the file inaction
if theECONNRESET
error is caught.The handler is already able to remove some failed uploads (when the allowed size is exceeded, see the fragment below) and could be modified to set
deleteFile = true
if any error occurs.remix/packages/remix-node/upload/fileUploadHandler.ts
Lines 135 to 151 in 32300ec
Suggestions
My idea is to add a
catch
block beforefinally
, setdeleteFile
and rethrow. Thefinally
will still be executed, clean up and the error will be rethrown to handle up in the stack.Special handling for
ECONNRESET
Delete file on any error
Beta Was this translation helpful? Give feedback.
All reactions