                             # create crashreport collection
                             crashreport = {}
                             _(fields).each (v,k) -> crashreport[k] = v
-                            crashreport.files = stored_files
+
+                            # parse attachments
+                            crashreport.files = parse_attachments(stored_files)
+
                             # TODO: put attachment files into an array and replace /\./,'_'
 
                             #console.log "Crashreport: " + util.inspect(crashreport) #debug



save_crashreport = (crashreport, cb) ->
    q = DB_CRASHREPORTS.find({'id':crashreport.id}).upsert().update(crashreport)
    q.run (err) ->
        if err?

                console.log "remove_files error:"
                console.log err

parse_attachments = (files) ->
    attachments_arr = []
    _(files).each (property, fileid) ->
        if fileid.match /attachment\.\d+/i
            attachments_arr.push(property)
            delete files[fileid]
    files["attachments"] = attachments_arr if attachments_arr.length > 0
    return files

init_import_api = (settings, app, db) ->

    DB_CRASHREPORTS = db.collection('crashreports')
