ファイルのダウンロード
早期アクセスモードでStratusコンポーネントを使用するには、support@zohocatalyst.comまでメールでお問い合わせください。
download()メソッドを呼び出すことで、File Store内の既存のフォルダからファイルをダウンロードできます。操作はファイルが保存されている一時URLを返します。
以下に示す2つの方法のいずれかでファイルをダウンロードできます。
両方のコードセクションで使用されている<FILE_INSTANCE>は、サンプルコードスニペットに示すように、特定のファイルに対して作成されたインスタンスです。これは、ダウンロードする特定のフォルダのファイルを参照します。
Delegateを使用する方法
このメソッドでは、以下のコード構文に示すように、Delegateを使用してファイルがダウンロードされます:
<FILE_INSTANCE>.download( fileDownloadDelegate : ZCatalystFileDownloadDelegate )
パラメータ:
- FileDownloadDelegate: ZCatalystFileDownloadDelegate型のインスタンスです。
サンプルコードスニペットを以下に示します:
func progress(fileRefId: String, session: URLSession, downloadTask: URLSessionDownloadTask, progressPercentage: Double, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
{
print("The percentage of file download is \(progressPercentage)")
}
func didFinish( fileRefId : String, fileResult : ( Data, URL ) )
{
print(“The file with reference id " + fileRefId + " is successfully downloaded.”)
}
func didFail( fileRefId : String, with error : ZCatalystError? )
{
print(“The file with reference id " + fileRefId + " download has been failed due to (ZCatalystError.self)”)
}
ZCatalystApp.shared.getFileStoreInstance().getFolderInstance(id : 105000000121098) .getFile(id : 332000000044009){(result) in
//フォルダIDとファイルIDをここに置き換えてください
switch result{
case .success ( let file) :
file.download( fileDownloadDelegate : self )
case .error( let error ) :
print( “Error occurred >>> ( error )” )
}
}
Completion Handlerを使用する方法
このメソッドでは、以下のコード構文に示すように、Completion Handlerを使用してファイルがダウンロードされます:
<FILE_INSTANCE>.download( completion : @escaping ( Result< ( Data, URL ), ZCatalystError > ) -> Void )
パラメータ:
- completion: 操作が成功した場合、completionブロックはファイルデータとファイルデータが保存されている一時URLを返します。それ以外の場合は、エラーを返します。
サンプルコードスニペットを以下に示します:
ZCatalystApp.shared.getFileStoreInstance().getFolderInstance(id: 105000000121098).getFile(fileId: 332000000044009) {(result) in
//これをあなたのフォルダIDに置き換えてください and File ID
switch result{
case .success(let file) :
file.download(){(result) in
switch result{
case .success(let downloaded_file) :
print("The file is successfully downloaded.")
case .error(let error) :
print( "Error occurred >>> \( error )" )
}
}
case .error(let error) :
print( "Error occurred >>> \( error )" )
}
}
最終更新日 2026-03-24 17:38:39 +0530 IST
Yes
No
Send your feedback to us