我有一個自動例程,可以由用戶觸發將圖像上傳到Amazon S3。用戶通常會有超過500個項目上傳,我正在努力尋找一種不會讓程序超時的方法。如何防止在Coldfusion中多文件上傳超時?
現在我這樣做:
<form action="hs_import.cfm?ansicht=Bilder&RequestTimeout=5000" method="post" name="uploader">
...
<input type="button" OnClick="bilder_upload()" value="#tx_gen_run#">
<input type="hidden" name="artikel_uploaden" value="ja">
<input type="hidden" name="ansicht" value="imageloader">
</form>
觸發JavaScript函數,這將觸發我的上傳(沒有詳細說明):
<cfif isdefined("artikel_uploaden")>
<cfscript>
S3 variables
</cfscript>
<!--- get img paths to upload --->
<cfquery datasource="db" name="img_paths">
SELECT DISTINCT imgpath
</cfquery>
<cfif img_paths.recordcount GT 0>
<cfloop query="img_paths">
<cfif img_paths.typ NEQ "img">
<cfset variables.testFilePath = img_paths.bildpfad & img_paths.bilddateiname>
<cfset variables.fileExt = ListLast(variables.testFilePath, ".")>
<!--- get image --->
<cfhttp timeout="45"
throwonerror="no"
url="#variables.testFilePath#"
method="get"
useragent="Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12"
getasbinary="yes"
result="variables.objGet">
<!--- validate --->
<!--- upload 4 sizes (s,m,l,xl) to S3 --->
<cftry>
<cfset objImage = ImageNew(variables.objGet.FileContent)>
<cfimage source="#objImage#" action="write" quality=".99" destination="#variables.tempDirectory#_base_#img_paths.bilddateiname#" overwrite="yes">
<cfset variables.basePath = variables.tempDirectory & "_base_" & img_paths.bilddateiname>
<cfimage action="read" source="#variables.basePath#" name="base">
<cfset variables.imageSrc = variables.tempDirectory>
<cfscript>
if (ImageGetWidth(base) LT ImageGetHeight(base)) {
// portrait
} else {
// landscape/square
}
// cleanup
</cfscript>
<!--- create IMG entry in media table --->
<cfquery datasource="db"></cfquery>
</cfif>
<cfcatch>
<cfset variables.errorCount = variables.errorCount+1>
<cfset variables.failedLoads = variables.failedLoads & img_paths.bilddateiname & " (" & tx_pop_error & ":" & tx_errors_import_ext & "), ">
</cfcatch>
</cftry>
</cfif>
</cfloop>
<!--- alert on success and errors --->
</cfif>
這工作不錯,但瀏覽器只是掛起如果圖像數量過大,則會出現/超時,所以我通常會查看永不完成的加載屏幕,並且不會提示成功/錯誤。
問題:
什麼將是處理大文件上傳這樣一個更好的選擇?例如,這是否應該進入cfschedule
,以便它可以在後臺運行?
感謝的提示!
hm。我喜歡這個主意。你能告訴我如何在一個變量中存儲「100個查詢」嗎?從來沒有這樣做過。 Thx到目前爲止。 – frequent
@frequent:我從內存中完成這個工作(不再用CF編寫代碼),只是創建一個變量,並將查詢存儲在分隔符中,用分號分隔。然後每隔100個循環,將變量的值轉儲到cfquery中。我記得,你將需要使用PreserveSingleQuotes。 – Limey