         log "Saved subject #{subject.id}"
 
         # Locations array has been transformed into [{"mime type": "URL to upload"}]
+        successCount = 0
         for location, ii in subject.locations
           for type, url of location
             headers = {'Content-Type': mime.lookup imageFileNames[ii]}

            if response?
              if 200 <= response.statusCode < 400
                log "Uploaded image #{imageFileNames[ii]}"
                newSubjectIDs.push subject.id
              else
                error = response.body


              await subject.delete().then(defer _).catch(console.error.bind console)
              break

          # Deal with multi-image subject. Only add new subject id once and if all images put successfully.
          newSubjectIDs.push subject.id if successCount is subject.locations.length

if newSubjectIDs.length is 0
  log 'No subjects to link'
else
