File Uploader
See VGSFileProvider , FileState in API references.
VGSFileProvider
is a part of VGS Collect Android SDK. The instance provides means for file management inside the SDK. It allows managing files inside the SDK by attach
, detach
and get
file general info methods.
To manage the files in your application, you need to use VGSFileProvider
. To get it, call getFileProvider() from your VGSCollect
object.
There are a few actions that may be of interest for managing files:
Save file with
attachFile()
for sending in the future to the Proxy Server.Remove one by one or all together using
detachFile()
ordetachAll()
.Overview of all already attached files with
getAttachedFiles
.
Also, don't forget to implement onActivityResult
callback.
private val vgsForm = VGSCollect(this, "<VAULT_ID>", Environment.<SANDBOX> )\n
fun getFileProvider() {
val fileProvider: VGSFileProvider = vgsForm.getFileProvider()
}\n
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
vgsForm.onActivityResult(requestCode, resultCode, data)
}
Limitations
Please note, for now, there are some limitations on the data you can upload:
Maximum upload file size: files should not be bigger than 20MB.
Maximum file count: only one file at a time can be selected and submitted.
Attach file
Register a file to be uploaded when your request is finished and sent to the server. Before attaching a file using the SDK, you should define fieldName
. Usually, it is similar to a field name in the JSON path in your inbound route filters.
After attachFile
is called, Android will open your device's content provider to choose a file.
Don't forget to detach the file after submitting it to the VGS Proxy. After the file was attached, it stays in local storage and is send in every request until you perform final cleanup by calling
onDestroy()
.
private val vgsForm = VGSCollect( this, "<VAULT_ID>", Environment.<SANDBOX> )\n
private fun attachFile() {
val fileProvider: VGSFileProvider = vgsForm.getFileProvider()
fileProvider.attachFile(activity, "<field_name>")
}
Get attached files
This method is used to get attached files to review them before sending. It returns all states of the files that are attached to the VGSCollect
instance.
private val vgsForm = VGSCollect( this, "<VAULT_ID>", Environment.<SANDBOX> )\n
private fun getAttachedFiles() {
val fileProvider: VGSFileProvider = vgsForm.getFileProvider()
val states:List<FileState> = fileProvider.getAttachedFiles()
}
Detach file
You can detach one or all files attached to the SDK earlier.
To detach one separate file call the detachFile
method with the FileState
object as a parameter. Also, you can detach all files at once by detachAll
.
private val vgsForm = VGSCollect( this, "<VAULT_ID>", Environment.<SANDBOX> )\n
private fun detachFile(fileInfo:FileState) {
val fileProvider: VGSFileProvider = vgsForm.getFileProvider()
fileProvider.detachFile(fileInfo)
}\n
private fun detachAll() {
val fileProvider: VGSFileProvider = vgsForm.getFileProvider()
fileProvider.detachAll()
}
Last updated