iOS SDK Samples - Files Operations
Upload Files to Zoho File System (ZFS) using completion
guard let filePath = testBundle.path(forResource: "photos/attch", ofType: "png", inDirectory: "resources" ) else
{
throw( ZCRMError.inValidError(code: ErrorCode.invalidData, message: "Failed to get the resource file", details: nil) )
}
let data = tryData(contentsOf: URL(fileURLWithPath: filePath))
/*- Parameters:
- fileName : Name of the image to be uploaded
- fileData : Data object of the image to be uploaded
- inline : To upload the file as an inline image this param must be true*/
ZCRMSDKUtil.uploadFile( fileName: filePath.lastPathComponent(), fileData: data, inline: false ) { result in
switch result
{
case.success(let fileId, let response) :
print ("ResponseJSON : \( response.responseJSON )")
case .failure(let error) :
print ( "Throws exception : \(error)" )
}
}
Upload File to ZFS using delegate
/*- Parameters:
- fileRefId : The reference Id of the upload request to identify the progress of the individual upload request
- filePath : The absolute path of the photo to be uploaded
- inline : To upload the file as an inline image this param must be true
- fileUploadDelegate : FileUploadDelegate object which helps to track the progress, completion and error of an upload request*/
guard let filePath = testBundle.path(forResource: "photos/JAVAFile", ofType: "java", inDirectory: "resources" ) else
{
throw( ZCRMError.inValidError(code: ErrorCode.invalidData, message: "Failed to get the resource file", details: nil) )
}
ZCRMSDKUtil.uploadFile(fileRefId: "Upload file request", filePath: filePath, inline: false, fileUploadDelegate: self)
Get files from ZFS using completion
ZCRMSDKUtil.downloadFile(byId: "76543456765") { result in
switch result
{
case .success(let response) :
print ("ResponseJSON : \( response.responseJSON )")
case .failure(let error) :
print ( "Throws exception : \(error)" )
}
}
Get files from ZFS using delegate
ZCRMSDKUtil.downloadFile(byId: "345678987654567", fileDownloadDelegate: self)