Upload a File

You can upload a file to an existing folder in the File Store, by calling the uploadFile() method. After the file is uploaded in the folder, a unique File ID will be generated for it. You can upload an image, text document, CSV, or any type of file you need upto 100MB of file size.

You can upload the file in one of the following four ways, as discussed below. The <FOLDER_INSTANCE> used in the code sections of all the methods below is the instance defined in the Folder Instance page. This will refer to the folder that the file must be uploaded in.

By passing the File URI Scheme

You can upload the file to the folder of the given folder instance by passing the file’s URI scheme as an argument to the uploadFile() method:

    
copy
<FOLDER_INSTANCE>.uploadFile( uri: Uri, success: (ZCatalystFile) → Unit, failure: ((ZCatalystException) → Unit)?, progress: ((Long, Long, Double) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ZCatalystFile>>?

Parameters:

  • uri: The File URI scheme of the file to be uploaded

A sample code snippet is shown below:

    
copy
ZCatalystApp.getInstance().getFileStoreInstance().getFolderInstance(2823000000006561).uploadFile("/src.example.com/files/productImage.png", { println(" >> File Upload Success -$it") }, { println(" >> File Upload Failed -$it") })

By passing the file path

You can upload the file to the folder of the given folder instance by passing its file path in the local system an argument to the uploadFile() method:

    
copy
<FOLDER_INSTANCE>.uploadFile( filePath: String, success: (ZCatalystFile) → Unit, failure: ((ZCatalystException) → Unit)?, progress: ((Long, Long, Double) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ZCatalystFile>>?

Parameters:

  • filepath: The file path of the file to be uploaded

A sample code snippet is shown below:

    
copy
ZCatalystApp.getInstance().getFileStoreInstance().getFolderInstance(2823000000006561).uploadFile("/Desktop/HelplineCard.jpg", { println(" >> File Upload Success -$it") }, { println(" >> File Upload Failed -$it") })

By passing the File URI Scheme and file name

You can upload the file to the folder of the given folder instance by passing both File URI scheme and the file name as individual arguments to the uploadFile() method:

    
copy
<FOLDER_INSTANCE>.uploadFile( uri: Uri, fileName: String, success: (ZCatalystFile) → Unit, failure: ((ZCatalystException) → Unit)?, progress: ((Long, Long, Double) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ZCatalystFile>>?

Parameters:

  • uri: The File URI scheme of the file to be uploaded
  • fileName: The name of the file to be uploaded

A sample code snippet is shown below:

    
copy
ZCatalystApp.getInstance().getFileStoreInstance().getFolderInstance(2823000000006561).uploadFile("/src.example.com/files", "productImage.png", { println(" >> File Upload Success -$it") }, { println(" >> File Upload Failed -$it") })

By passing the file path and file name

You can upload the file to the folder of the given folder instance by passing both the file path in the local system and the file name as the arguments to the uploadFile() method:

    
copy
<FOLDER_INSTANCE>.uploadFile( filePath: String, fileName: String, success: (ZCatalystFile) → Unit, failure: ((ZCatalystException) → Unit)?, progress: ((Long, Long, Double) → Unit)? ): ZCatalystRequest<ZCatalystResponse<ZCatalystFile>>?

Parameters:

  • filepath: The file path of the file to be uploaded
  • fileName: The name of the file to be uploaded

A sample code snippet is shown below:

    
copy
ZCatalystApp.getInstance().getFileStoreInstance().getFolderInstance(2823000000006561).uploadFile("/Desktop", "HelplineCard.jpg", { println(" >> File Upload Success -$it") }, { println(" >> File Upload Failed -$it") })

By passing the file as inputStream and the file name

You can upload the file to the folder of the given folder instance by passing both the file as inputStream and the file name as the arguments to the uploadFile() method:

    
copy
<FOLDER_INSTANCE>.uploadFile(stream: InputStream, fileName: String, success: (ZCatalystFile) -> Unit, failure: ((ZCatalystException) -> Unit)? = null, progress: ((bytesWritten: Long, contentLength: Long, percentage: Double) -> Unit)? = null) : ZCatalystRequest<ZCatalystResponse<ZCatalystFile>>?

Parameters:

  • stream: The inputStream of the file
  • fileName: The name of the file to be uploaded

A sample code snippet is shown below:

    
copy
val file = File("/Desktop/HelplineCard.jpg") val inputStream: InputStream = FileInputStream(file) ZCatalystApp.getInstance().getFileStoreInstance().getFolderInstance(2823000000006561).uploadFile(inputStream, { println(" >> File Upload Success -$it") }, { println(" >> File Upload Failed -$it") })

Last Updated 2023-09-03 01:06:41 +0530 +0530