最終更新日 :
2025年3月31日
警告 :
すべてのモバイル機能とモバイル関連機能は ColdFusion(2025リリース)で削除されました。
詳しくは、ColdFusion の非推奨の機能を参照してください。
開始する前に、ファイルシステム関数を参照してください。
デバイスからのファイルのアップロード
<cfclientsettings enabledeviceapi="true" enabledebuglog="true"> <cfclient> <cffunction name="uploadSuccess" > <cfset alert("uploaded")> </cffunction> <cffunction name="uploadError" > <cfargument name="err" > <cfset alert(err.code)> </cffunction> <cftry> <cfscript> cfclient.file.write("a.txt","hello"); cfclient.file.upload("a.txt","http://<Your-CF-Server>:8500/fileUpload/files/upload.cfm",uploadSuccess,uploadError); </cfscript> <cfcatch type="Any" > <cfset alert("exception " & cfcatch.message)> </cfcatch> </cftry> </cfclient>
デバイスへのファイルのダウンロード
<cfclientsettings enabledeviceapi="true" enabledebuglog="true"> <cfclient> <cffunction name="uploadSuccess" > <cfargument name="obj" > <cfset alert("downloaded "+obj)> <cfset alert(cfclient.file.read('b.txt'))> </cffunction> <cffunction name="uploadError" > <cfargument name="err" > <cfset alert(err.code)> </cffunction> <cftry> <cfscript> cfclient.file.download("http://<Your-CF-Server>:8500/fileUpload/files/b.txt","b.txt",uploadSuccess, uploadError); </cfscript> <cfcatch type="Any" > <cfset alert("exception " & cfcatch.message)> </cfcatch> </cftry> </cfclient>
ディレクトリの作成
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset cfclient.file.createDirectory('MyDir')> </cfclient>
ディレクトリの削除
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfif cfclient.file.directoryExists('MyDir')> <cfset cfclient.file.removeDirectory('MyDir',true)> </cfif> </cfclient>
作業用ディレクトリの取得
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset cwd = cfclient.file.getWorkingDirectory()> </cfclient>
ディレクトリのコピー
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfif cfclient.file.directoryExists('dir1')> <cfset cfclient.file.removeDirectory('dir1',true)> </cfif> <cfset dir1Obj=cfclient.file.createDirectory('dir1')> <cfif cfclient.file.directoryExists('dir2')> <cfset cfclient.file.removeDirectory('dir2',true)> </cfif> <cfset dir2Obj=cfclient.file.createDirectory('dir2')> <cfset cfclient.file.copyDirectory(dir2Obj.fullPath,dir1Obj.fullPath)> </cfclient>
ファイルの読み取り
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset fileContent = cfclient.file.read('MyFile.txt')> </cfclient>
Base64 テキストとしてのファイルの読み取り
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset opt = cfclient.camera.getOptions()> <cfset res = cfclient.camera.getPicture(opt,false)> <cfset imgStr=cfclient.file.readAsBase64(res)> </cfclient>