<cfif StructKeyExists(FORM, "submit")>
<cfparam name = "FORM.skipFirst" default = "0" />
<cffile action = "upload"
fileField = "csv"
destination = "#GetTempDirectory()#"
nameConflict = "overwrite"
accept = "text/plain, text/csv, text/comma-separated-values, application/octet-stream, application/vnd.ms-excel" />

<cfset fileName = cffile.clientFilename />
<cfset fileExt = cffile.clientFileExt />
<!--- read the file line by line to avoid running out of memory --->
<cfset filePath = "#GetTempDirectory()##fileName#.#fileExt#" />
<cfset fileReader = CreateObject("java", "java.io.FileReader").Init(JavaCast("string", filePath)) />
<cfset bufferedReader = CreateObject("java", "java.io.BufferedReader").Init(fileReader) />
<cfset lineReader = CreateObject("java", "java.io.LineNumberReader" ).Init(bufferedReader) />
<cfset request.lineData = lineReader.readLine() />

<cfloop condition="StructKeyExists(request, 'lineData')">
<cfset lineNum = lineReader.GetLineNumber() />
<cfif form.skipFirst EQ 1 AND lineNum EQ 1>
<!--- this is the only way I could get this to work... --->
<cfset request.lineData = lineReader.readLine() />
</cfif>
<!--- after every 25 lines, clean up the garbage --->
<cfif lineNum % 25 EQ 0>
<cfset runtime = CreateObject("java", "java.lang.Runtime").getRuntime() />
<cfset runtime.gc() />
</cfif>
<cfset vals = ListToArray(request.lineData) />
<cfset Model.updateAttribute(URL.id, vals) />
<cfset request.lineData = lineReader.readLine() />
</cfloop>

<!--- this is causing trouble
<cffile action = "delete" file = "#GetTempDirectory()##fileName#.#fileExt#" /> --->
<cfset flash("notice", "Your update was successful.") />
<cflocation url = "?page=#URL.page#&action=browse&id=#URL.id#" />
</cfif>