npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ufs-client-js

v1.7.0

Published

品高统一文件服务(UFS) JSSDK

Downloads

223

Readme

ufs-client-js

该JSSDK支持在Web、BT、Weex中使用,内部会自动适配所在框架环境。SDK暂不支持:应用注册、应用注销、预览 API。

安装&引入

npm安装:

npm install ufs-client-js --save

导入模块:

// web模块化工程中引入
import { StorageClient } from "ufs-client-js";

// weex中引入
const ufs = require("ufs-client-js");

BUI安装

假如是BT或者BUI的工程,可以直接下载 src/ufs-bt-plugin.js,并将其引入页面:

<script src="./script/ufs-bt-plugin.js"></script>

该js会把 ufs 对象暴露在window下面,可以通过 ufs.upload 进行直接操作。

使用指南

Web 示例

以选择文件上传为例, BUI中如果使用input type='file'选择的文件也可以通过这种方式操作。

<input id="fileInput" type="file">

function testUpload() {
    //根据实际情况更换地址
    let apiServer = "http://ufs-dev.bingosoft.net/api/";
    //初始化对象,并传入 AccessToken,可以通过app.link.getToken获取
    let storageClient = new StorageClient(apiServer, {
        accessToken: "ead89b24-4fe1-48cd-813f-1947c0bca62f"
    });
    //获取文件对象
    let files = document.getElementById("fileInput").files;
    if(files.length==0){
        alert("请先选择文件");
        return;
    }
    //执行上传
    storageClient.upload({
        file: files[0]
    }).then((data, resp) => {
        alert(JSON.stringify(data));
        //上传完成并得到路径
        storageClient.urlFor({
            fileId: data.id
        }).then(urlInfo => {
            alert(JSON.stringify(urlInfo));
        });
    }).catch((err) => {
        alert(JSON.stringify(err));
    });
}

Weex示例

以拍照上传为例:

testUpload(){
    //根据实际情况更换地址
    let apiServer = "http://ufs-dev.bingosoft.net/api/";
    let storageClient = new StorageClient(apiServer,{
        accessToken:"ead89b24-4fe1-48cd-813f-1947c0bca62f"
    });
        //使用Camera模块
    let camera = weex.requireModule("CameraModule");
    let params ={};

    //场景:拍照上传
    camera.captureImage(params, (res)=>{
        let filePath = res.filePaths[0];
        if(!filePath){this.$toast("上传文件不存在!");return;}
        
        //压缩图片再上传
        camera.compressImage({
            sourcePath:filePath,
            quality:50
        },(res)=>{
            filePath = res.filePaths[0];
            this.$alert(filePath);
            
            //执行上传文件
            storageClient.upload({
                file:filePath
            }).then((data,resp)=>{
                this.$alert(data);
                
                //上传完成并得到路径
                storageClient.urlFor({
                    fileId: data.id
                }).then(url => {
                    this.$alert(url);
                });
            }).catch((resp)=>{
                this.$alert(resp);
            });
        });

    });
}

BT/BUI示例


//选择图片或者拍照
navigator.camera.getPicture(function (imageURI) {
        window.resolveLocalFileSystemURI(imageURI, gotFileEntry, onFileFail);
        function gotFileEntry(fileEntry) {
            filePath = fileEntry.fullPath;
            //得到图片路径并上传
            upload(filePath);
        }
        function onFileFail(err) {
            app.alert(err);
        }
    },
    function (message) {
        app.alert('get picture failed');
    }, {
        quality: 50,
        destinationType: navigator.camera.DestinationType.FILE_URI,
        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
    }
);

function upload(filePath) {
    //执行上传
    ufs.upload({
        server:apiServer,
        token:token,
        file:filePath
    },(res)=>{
        var fileId = res.id;
        app.alert("fileId:"+res.id);

        //根据fileId获取上传后的路径
        ufs.urlFor({
            server:"http://ufs-dev.bingosoft.net/api/",//替换成实际的
            token:"95945422-a5a9-43c8-b126-51aea17367f3", //替换成实际的
            fileId:fileId
        },(res)=>{
            app.alert(res);
        },(err)=>{
            app.alert(err);
        });
    },(err)=>{
        alert(err);
    });
}

API 参考

更多API的接口,请参考:

Web & Weex => UFS API

BUI => UFS-BT API