File Picker

File picker will help merchants to read any form of document, such as pdf, image, video, etc. from a user's filesystem.

selectFile(mimeType: string, allowMultiple: boolean) => Promise

Description:
This method opens up a user interface that allows the user to pick up an image/video/audio/document (based on mimeType).

Promise - The promise resolution returns a JS object with the URI, filename and size of the taken image.

Request Parameters

Parameter NameTypeDescription
mimeTypestringThe type of content/file to select. This value can either be ‘image’, ‘video’, ‘audio’, or ‘document’.
allowMultiplebooleanAllow multiple files to be picked up at once. This option only works on Android and not on iOS

Usage:

sdk.selectFile(‘mimeType’, 'allowMultiple’)
  .then((data) => {
    console.log('Value received = ' + data)
})
  .catch((err) => {})

Response Parameter

Promise<string>
A promise with the desired value or error if there is some issue. Promise failure reasons can be as follows:

CodeDescription
USER_CANCELEDUser canceled the file selection flow
INTERNAL_ERRORPhonePe’s internal error
Response : 

Promise<any> - The promise resolution returns an array of maps describing the files selected by the user. 

Promise resolve:

[{
“uri”: “content://main/folder/image.jpeg”,
“fileName”: “image.jpeg”,
“size_in_bytes”: “12345” 
}]

Promise reject:
{
  'error_code': USER_CANCELED
}

readFile(uri: string, offset:number, length: number) => Promise

Description: This method needs a URI to read a file. This URI must be first returned through the selectFile() method. The file can be read in chunks or can be read in one go based on the offset and length parameters. The size of the file is already returned in the selectFile() method’s response.

Promise - The promise resolution returns a JS object with the URI of the taken image.

Usage:

Suppose the size of the file is 100

You can read whole file together 
readFile(uri, 0,100(size))

or Read multipart : You can fetch using the different sizes.

readFile(uri, 0, 10(size)) - In response you will get 0-10 
readFile(uri, 10, 90(size)) - In response you will get data from 10-100



PhonePe.PhonePe.build(PhonePe.Constants.Species.web).then((sdk) => {
    sdk.readFile(‘uri’,1, 100)
  .then((data) => {
    console.log('Value received = ' + data)
})
  .catch((err) => {})
})

Response Parameter

Parameter NameTypeDescription
uristringURI (file path) returned from the selectFile() method call.
offsetnumberThis is the offset (in bytes) from starting where the file will be read from.
lengthnumberThe data length (in bytes) to read from the offset.

Promise<any>
A promise resolution with the grant token. Promise rejection if the grant token fetching failed.

Response : 

Promise<any> - The promise resolution returns an array of maps describing the files selected by the user. 

Promise resolve:
{
“uri”: “content://main/folder/image.jpeg”,
“base64Data”: “ABCD1234ABCD”
}

Promise reject:
{
  'error_code': PERMISSION_DENIED
}
CodeDescription
PERMISSION_DENIEDThis URI was not first retrieved through the selectFile() method call.
INTERNAL_ERRORPhonePe’s internal error

📘

The URIs allowed to be read through the readFile() method should be retrieved from the selectFile() method first. The client should maintain a map to ensure this.