Skip to main content
Version: v3+

TransferFile

The TransferFile file transfer module can transfer files from the "Side Service" of the Mini Program to the "Device App".

getOnbox​

Returns an Onbox object for sending files.

Types​

() => Onbox

Example​

const outbox = transferFile.getOutbox()

Onbox object​

enqueFile​

Types​
(fileName: string, params: object) => FileObject
PropertiesDescriptionRequiredType
fileNameFile PathNOstring
paramsParameters passed to Device AppNOobject

FileObject reference FileObject Type definition

Example​
const fileObject = onbox.enqueueFile('data://download/test.png', { type: 'image', name: 'fdsa' })

getInbox​

Returns an Inbox object for receiving files.

Types​

() => Inbox

Example​

const inbox = transferFile.getInbox()

Inbox Object​

getNextFile​

Types​
() => FileObject

FileObject type reference FileObject type definition

Code Example​
const fileObject = onbox.enqueueFile('data://download/test.png', { type: 'image', name: 'fdsa' })

Full Example​

const outbox = tranfserFile.getOutBox()

AppSideService({
onInit() {
const fileObject = outbox.enqueueFile('data://download/1.png', {type: "image", name: "fdsa"})

file.on('progress', (event) => {
console.log("progress total size", event.data.fileSize)
console.log("progress total size", event.data.loadedSize)
})

file.on('change', (event) => {
if (event.data.readyState === 'transferred') {
console.log('transfered file success')
} else (event.data.readyState === 'error') {
console.log('error')
}
})
}
})