         if err then throw err
 
   copyImages = (file, move)->
-    oldName = file.getFieldValue("title").split(/\.(?=[^.]*$)/)[0]
-    newName = file.getFieldValue("link").split(/\.(?=[^.]*$)/)[0]
     for type in types
-      newLink = file.getFieldValue(type).replace newName, oldName
       oldLink = file.getFieldValue type
+      newLink = file.getFieldValue('title').replace /\.(?=[^.]*$)/, '_'+type+'.'
       if move
         fs.move dir+oldLink, dir+newLink
       else
-        #newLink = newLink.replace '\$.', '_copy_'+Date.now()+'.'
         fs.writeFileSync dir+newLink, fs.readFileSync(dir+oldLink)
-
-      file.setFieldValue type, newLink
-      console.log(type, newLink)
+      file.setFieldValue type, newLink unless type is "link"
+    file
 
 
   createImages = (file, req) ->

    newFileName = oldFileName.replace /\.(?=[^.]*$)/, "_"+Date.now()+"_copy."
    fs.writeFileSync dir+newFileName, fs.readFileSync dir+oldFileName
    file.setFieldValue 'link', newFileName
    createImages file, req
    file.setFieldValue 'title', newFileName
    file.save ->
      req.io.broadcast "updateCollection", "Files"


        if fs.existsSync(dir+title) is true
          title = title.replace /\.(?=[^.]*$)/, "_"+Date.now()+"_copy."
          file.setFieldValue "title", title
        file = copyImages file, true # move = true, only moving
        file.setFieldValue "link", title
      file.save ->
        console.log("saveFile", file)
        req.io.broadcast 'updateCollection', cfg.collectionName


  app.post "/uploadFile", auth, (req,res)->
    form = new multiparty.Form
    form.parse req, (err, fields, files)->
      if err then return console.log 'formparse error', err
