File API の使用

警告 :

すべてのモバイル機能とモバイル関連機能は ColdFusion(2025リリース)で削除されました。

詳しくは、ColdFusion の非推奨の機能を参照してください。

開始する前に、ファイルシステム関数を参照してください。

デバイスからのファイルのアップロード

<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;>
<cfclient>
<cffunction name=&quot;uploadSuccess&quot; >
<cfset alert(&quot;uploaded&quot;)>
</cffunction>
<cffunction name=&quot;uploadError&quot; >
<cfargument name=&quot;err&quot; >
<cfset alert(err.code)>
</cffunction>
<cftry>
<cfscript>
cfclient.file.write(&quot;a.txt&quot;,&quot;hello&quot;);
cfclient.file.upload(&quot;a.txt&quot;,&quot;http://<Your-CF-Server>:8500/fileUpload/files/upload.cfm&quot;,uploadSuccess,uploadError);
</cfscript>
<cfcatch type=&quot;Any&quot; >
<cfset alert(&quot;exception &quot; & cfcatch.message)>
</cfcatch>
</cftry>
</cfclient>
<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;> <cfclient> <cffunction name=&quot;uploadSuccess&quot; > <cfset alert(&quot;uploaded&quot;)> </cffunction> <cffunction name=&quot;uploadError&quot; > <cfargument name=&quot;err&quot; > <cfset alert(err.code)> </cffunction> <cftry> <cfscript> cfclient.file.write(&quot;a.txt&quot;,&quot;hello&quot;); cfclient.file.upload(&quot;a.txt&quot;,&quot;http://<Your-CF-Server>:8500/fileUpload/files/upload.cfm&quot;,uploadSuccess,uploadError); </cfscript> <cfcatch type=&quot;Any&quot; > <cfset alert(&quot;exception &quot; & cfcatch.message)> </cfcatch> </cftry> </cfclient>
<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;>

<cfclient>

<cffunction name=&quot;uploadSuccess&quot; >
<cfset alert(&quot;uploaded&quot;)>
</cffunction>

<cffunction name=&quot;uploadError&quot; >
<cfargument name=&quot;err&quot; >
<cfset alert(err.code)>
</cffunction>

<cftry>
<cfscript>

cfclient.file.write(&quot;a.txt&quot;,&quot;hello&quot;);
cfclient.file.upload(&quot;a.txt&quot;,&quot;http://<Your-CF-Server>:8500/fileUpload/files/upload.cfm&quot;,uploadSuccess,uploadError);

</cfscript> 
<cfcatch type=&quot;Any&quot; >
<cfset alert(&quot;exception &quot; & cfcatch.message)>
</cfcatch>
</cftry>

</cfclient>

デバイスへのファイルのダウンロード

<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;>
<cfclient>
<cffunction name=&quot;uploadSuccess&quot; >
<cfargument name=&quot;obj&quot; >
<cfset alert(&quot;downloaded &quot;+obj)>
<cfset alert(cfclient.file.read('b.txt'))>
</cffunction>
<cffunction name=&quot;uploadError&quot; >
<cfargument name=&quot;err&quot; >
<cfset alert(err.code)>
</cffunction>
<cftry>
<cfscript>
cfclient.file.download(&quot;http://<Your-CF-Server>:8500/fileUpload/files/b.txt&quot;,&quot;b.txt&quot;,uploadSuccess,
uploadError);
</cfscript>
<cfcatch type=&quot;Any&quot; >
<cfset alert(&quot;exception &quot; & cfcatch.message)>
</cfcatch>
</cftry>
</cfclient>
<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;> <cfclient> <cffunction name=&quot;uploadSuccess&quot; > <cfargument name=&quot;obj&quot; > <cfset alert(&quot;downloaded &quot;+obj)> <cfset alert(cfclient.file.read('b.txt'))> </cffunction> <cffunction name=&quot;uploadError&quot; > <cfargument name=&quot;err&quot; > <cfset alert(err.code)> </cffunction> <cftry> <cfscript> cfclient.file.download(&quot;http://<Your-CF-Server>:8500/fileUpload/files/b.txt&quot;,&quot;b.txt&quot;,uploadSuccess, uploadError); </cfscript> <cfcatch type=&quot;Any&quot; > <cfset alert(&quot;exception &quot; & cfcatch.message)> </cfcatch> </cftry> </cfclient>
<cfclientsettings enabledeviceapi=&quot;true&quot; enabledebuglog=&quot;true&quot;>
<cfclient>
<cffunction name=&quot;uploadSuccess&quot; >
<cfargument name=&quot;obj&quot; >

<cfset alert(&quot;downloaded &quot;+obj)>
<cfset alert(cfclient.file.read('b.txt'))>
</cffunction>

<cffunction name=&quot;uploadError&quot; >
<cfargument name=&quot;err&quot; >

<cfset alert(err.code)>

</cffunction>

<cftry>
<cfscript>

cfclient.file.download(&quot;http://<Your-CF-Server>:8500/fileUpload/files/b.txt&quot;,&quot;b.txt&quot;,uploadSuccess,
uploadError);

</cfscript> 
<cfcatch type=&quot;Any&quot; >
<cfset alert(&quot;exception &quot; & cfcatch.message)>
</cfcatch>
</cftry>

</cfclient>

ディレクトリの作成

<cfclientsettings enableDeviceAPI=true>
<cfclient>
<cfset cfclient.file.createDirectory('MyDir')>
</cfclient>
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset cfclient.file.createDirectory('MyDir')> </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> <cfif cfclient.file.directoryExists('MyDir')> <cfset cfclient.file.removeDirectory('MyDir',true)> </cfif> </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> <cfset cwd = cfclient.file.getWorkingDirectory()> </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> <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>
 
<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>
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset fileContent = cfclient.file.read('MyFile.txt')> </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>
<cfclientsettings enableDeviceAPI=true> <cfclient> <cfset opt = cfclient.camera.getOptions()> <cfset res = cfclient.camera.getPicture(opt,false)> <cfset imgStr=cfclient.file.readAsBase64(res)> </cfclient>
<cfclientsettings enableDeviceAPI=true>
<cfclient>
 
<cfset opt = cfclient.camera.getOptions()>
<cfset res = cfclient.camera.getPicture(opt,false)>
<cfset imgStr=cfclient.file.readAsBase64(res)>
 
</cfclient>

ヘルプをすばやく簡単に入手

新規ユーザーの場合

Acrobat 購入相談

Acrobat 購入相談

Acrobat 購入相談

Acrobat 購入相談