Upload ServiceアップロードサービスThe Upload Service handles the parsing of multi-part/form-data from POST Requests, making the multi-part files available from either memory or from a specified location on the file system. アップロードサービスはPOSTリクエストからのmulti-part/form-dataの解析を処理し、メモリや、ファイルシステムの特定の場所のどちらかから、マルチパートのファイルを取得可能にします。 Configuration設定# ------------------------------------------------------------------- # # S E R V I C E S # # ------------------------------------------------------------------- # Classes for Turbine Services should be defined here. # Format: services.[name].classname=[implementing class] # # To specify properties of a service use the following syntax: # service.[name].[property]=[value] # Turbineのサービスのためのクラス群はここに定義します。 # フォーマット: services.[name].classname=[implementing class] # # サービスのプロパティを設定するには、以下の書式を使用します: # service.[name].[property]=[value] services.UploadService.classname=org.apache.fulcrum.upload.TurbineUploadService . . . # ------------------------------------------------------------------- # # U P L O A D S E R V I C E # # ------------------------------------------------------------------- # Whether the files should be automatically picked up by # ParameterParser. # ファイルをParameterParserにより自動的に取得するかどうか。 services.UploadService.automatic=false # # The directory where files will be temporarily stored. # # # ファイルが一時的に格納されるディレクトリ。 # services.UploadService.repository=. # # The maximum size of a request that will be processed. # # # 処理されるリクエストの最大サイズ。 # services.UploadService.size.max=1048576 # # The maximum size of a request that will have it's elements cached in # memory by TurbineUploadService class. # # # TurbineUploadServiceクラスにより、要素がメモリにキャッシュされる # リクエストの最大サイズ。 # services.UploadService.size.threshold=10240 Usage使用方法Change the automatic directive to true. With this set to true any multi-part/form-data requests which Turbine fields, will be parsed and the appropriate files made available to ParameterParser as FileItem objects. If this is set as false, the FileItems will have to be parsed out of RunData manually with the method getRequest() available from TurbineUpload. automaticディレクティブをtrueに変更してください。 trueに設定することで、Turbineのフィールドのmulti-part/form-dataリクエストはParameterParserにより解析、適切なファイルが作成されて、FileItemオブジェクトとして利用できるようになります。 これがfalseに設定されている場合、FileItemはTurbineUploadのgetRequest()メソッドで手動でRunDataを解析して取り出さなければなりません。 Set the remaining values to ones approriate for your installation. On Win32 file systems for the repository directive, an entry of the form: f:\path\to\upload\repository
残りの値を配置に合わせ適切に設定してください。 Win32ファイルシステムの場合のrepositoryディレクティブは、この形式のエントリ: f:\path\to\upload\repository
Create an HTML form of the type: HTMLのフォームはこの形式で作成してください: <form enctype="multipart/form-data" method="POST"> <input type="hidden" name="action" value="UploadExample" /> <input type="file" name="filename"> <input type="submit" value="upload" /> </form> The Upload Service manages if the FileItem is stored in Memory or in the Repository specified in TurbineReources.properties. It is also possible to overide the TurbineResources setting for the repository by using TurbineUpload.getRequest() to parse the request with a custom repository directory. The TurbineUpload object serves as a Facade to the Upload Service by making available static methods to manage the upload internally in your application. The FileItems can be accessed in an UploadExample Action class by: アップロードサービスはFileItemがメモリ内、またはTurbineReources.propertiesで設定されているリポジトリ内に格納されている場合に管理を行います。 リクエストを解析を行うTurbineUpload.getRequest()で使用されるTurbineResourcesのリポジトリの設定を、カスタムのリポジトリディレクトリにオーバライドすることも可能です。 TurbineUploadオブジェクトはアップロードを内部で管理するstaticメソッドによって、アプリケーションのアップロードサービスのファサードとしての役割も持ちます。 FileItemはUploadExample Actionクラスにおいてこのようにアクセス可能です:
public void doPerform(RunData data, Context context) throws Exception
{
//get the ParameterParser from RunData
//RunDataからParameterParserを取得します
ParameterParser params = data.getParameters();
//grab the FileItems available in ParameterParser
//ParameterParserからFileItemを取得します
FileItem fi = params.getFileItem("filename");
//do work on the FileItem
//get the file as a File
//or outputstream etc.
//FileItemを処理します。
//ファイルをFileオブジェクトとして、
//もしくはアウトプットストリーム等を取得します。
}
Once a new instance of the FileItem is created many public methods are available to work on the object, whether it is in temporary storage as memory or as a temporary file on part of the file system. All the temporary storage management and clean up occurs behind the scenes and is transparent to the application being based on Turbine. There is no need to manually clean up the FileItems as the FileItem object doesn't span Requests ( or RunData instances ) and the temporary files that use the file system are cleaned up in a finalize() method inherited from Object(). FileItemの新しいインスタンスが作成されると、 そのオブジェクトの多くのpublicメソッドが利用できるようになり、 それは一時的にメモリの中か、またはファイルシステム上にテンポラリファイルとして格納されることになります。 全ての一時的な格納場所の管理、クリーンアップの実行は舞台裏で行われ、Turbine上のアプリケーションからは気にする必要はありません。 FileItemを手動でクリーンアップする必要はありません。 FileItemオブジェクトは、Object()から継承したfinalize()メソッドによりファイルシステムがクリーンアップされることを利用し、リクエスト(またはRunDataインスタンス)とテンポラリファイルを結びつけないようになっています。 The TurbineUpload object and the FileItem object give all the functionality needed to manage this sort of operation or action at the application level. For more detailed information on the methods available to deal with uploaded files, view the relevant Javadocs for TurbineUpload, ParameterParser and FileItem. TurbineUploadオブジェクトとFileItemオブジェクトはアプリケーションレベルの操作やアクションで必要となる全ての機能を提供します。 アップロードされたファイルを扱う方法の詳細な説明はTurbineUpload、ParameterParser、FileItemに関連したJavadocを参照してください。 |