+ var file *os.File
+
+ // A file upload has three possible cases:
+ // 1) Upload a new file
+ // 2) Resume a partially transferred file
+ // 3) Replace a fully uploaded file
+ // We have to infer which case applies by inspecting what is already on the filesystem
+
+ // 1) Check for existing file:
+ _, err = os.Stat(destinationFile)
+ if err == nil {
+ // If found, that means this upload is intended to replace the file
+ if err = os.Remove(destinationFile); err != nil {
+ return err
+ }
+ file, err = os.Create(destinationFile + incompleteFileSuffix)
+ }