Skip to content

CuberQAQ/zepp-transfer-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

transfer-file

Polyfill of @zos/ble/transfer-file API for ZeppOS 2.0/2.1 device.

Corrently not support "progress" event or cancel sending task.

Some api were not tested. I don't know whether it could work correctly.

This repo is for ZeppOS device,not app-side. see CuberQAQ/zepp-fs-side: Polyfill of transferFile API for ZeppOS 1.0/2.0/2.1 app-side for app-side polyfill.

1. Install

Use Command npm i @cuberqaq/transfer-file --save to install transfer-file in your ZeppOS Miniapp project.

2. Import & Use

In your app-side JavaScript source file, use this to import transfer-file:

import { TransferFile } from "@cuberqaq/transfer-file";

Then you can use the methods in the same way you do with @zos/ble/TransferFile. API Document see Zepp OS Developers Documentation

3. Example:

Receiving File:

import { TransferFile } from "@cuberqaq/transfer-file";

const transferFile = new TransferFile()
const inbox = transferFile.getInbox()

Page({
  onInit() {
    inbox.on('NEWFILE', function() {
      const fileObject = inbox.getNextFile()

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

Send File:

import { TransferFile } from "@cuberqaq/transfer-file";

const transferFile = new TransferFile()
const outbox = transferFile.getOutbox()

Page({
  onInit() {
    const fileObject = outbox.enqueueFile("assets://logo.png", { test: 1})

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

By the way, it seems that the transfering speed could only reach 8kb/s :(

About

Polyfill of @zos/ble/transfer-file API for ZeppOS 2.0/2.1

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published