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

minio-deepc

v1.0.2

Published

minioclient

Downloads

4

Readme

MinioJS

Minio的官方客户端使用时必须依赖node.js, 无法在vite项目中使用, 此项目把minio的使用打包为纯js,可以在浏览器中直接调用minio的客户端

源码地址

https://gitee.com/zheyiw/minio-js-m

npm包地址

https://www.npmjs.com/package/minio-js

安装

yarn add minio-js

在vue3(vite)中使用

<template>
  <div id="nav">
    <p>vite中import使用miniojs上传文件</p>
    <input ref="input" type="file" @change="handleFiles" />
  </div>
</template>
<script lang="ts">
import { initMinio, putObject } from 'minio-js'

export default {
  methods: {
    handleFiles(event: any) {
      var f = event.target.files[0]
      let reader = new FileReader()
      reader.readAsArrayBuffer(f)
      reader.onload = function (e: any) {
        let res = e.target.result //ArrayBuffer
        //先初始化
        initMinio({
          endPoint: '192.168.2.98',
          port: 9002,
          useSSL: false,
          accessKey: 'admin',
          secretKey: '12345678',
        })
        //再上传
        putObject('act', res, f.name, function (err, data) {
          if (err) console.log(err)
          else {
             console.log('上传完成')
          }
        })
      }
    },
  },
}
</script>

使用说明

  • 在控制端可以设置bucket为public, 就可以拼接出资源的永久访问连接: http://ip:port/bucketname/filename
  • 文件名一定要重命名好, 上传了相同的文件名会覆盖之前的文件

直接使用Minio

如果上面封装的方法不满足, 可以直接使用Minio

import { Minio } from 'minio-js'

var minioClient = new Minio.Client(MinioConfig);
......

在html中使用

以js的方法使用, 直接引用MinioJs.js文件(文件很大, 按需引入)

<html>
  <head>
    <title>MinioJs</title>
  </head>
  <body>
    <div id="root">MinioJs</div>
    <script type="text/javascript" src="./MinioJs.js"></script>
    <script
      type="text/javascript"
      src="http://code.jquery.com/jquery-1.10.2.min.js"
    ></script>
    <div id="nav">
      <p>Minio文件上传:</p>
      <form id="form"><input type="file" name="file" id="file" /><br /></form>
    </div>
    <script type="text/javascript">
      $(function () {
        form.reset(); //清除浏览器记录的上次记录
        var file;
        $(form).on("change", "#file", function (e) {
          console.log(this.value); //文件路径
          console.log(this.files[0].name); //文件名

          //把文件以ArrayBuffer的形式读取后给Minio上传
          var f = this.files[0];
          let reader = new FileReader();
          reader.readAsArrayBuffer(f);
          reader.onload = function (e) {
            let res = e.target.result; //ArrayBuffer
            //先初始化
            MinioJs.initMinio({
              endPoint: "192.168.2.98",
              port: 9002,
              useSSL: false,
              accessKey: "admin",
              secretKey: "12345678",
            });
            //再上传
            MinioJs.putObject("bucket1", res, f.name, function (err, data) {
              if (err) console.log(err)
              else {
                console.log('上传完成')
              }
            });
          };
        });
      });
    </script>
  </body>
</html>

在Vue项目中以直接引入MinioJs.js的方式使用

把MinioJs.js放在public目录下面,在index.html中引入

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <link rel="icon" href="/favicon.ico" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Vite App</title>
  <script type="text/javascript" src="config.js"></script>
  <script type="text/javascript" src="MinioJs.js"></script>
</head>

<body>
  <div id="app"></div>
  <script type="module" src="/src/main.ts"></script>
</body>

</html>

使用

<template>
  <div id="nav">
    <p>MinioJs上传文件:</p>
    <input ref="input" type="file" @change="handleFiles" />
  </div>
</template>
<script lang="ts">
declare const MinioJs: any //定义

export default {
  methods: {
    handleFiles(event: any) {
      var f = event.target.files[0]
      let reader = new FileReader()
      reader.readAsArrayBuffer(f)
      reader.onload = function (e: any) {
        let res = e.target.result //ArrayBuffer
        //先初始化
        MinioJs.initMinio({
          endPoint: '192.168.2.98',
          port: 9002,
          useSSL: false,
          accessKey: 'admin',
          secretKey: '12345678',
        })
        //再上传
        MinioJs.putObject("bucket1", res, f.name, function (err, data) {
          if (err) console.log(err)
          else {
            console.log('上传完成')
          }
        });
      }
    },
  },
}
</script>

待办

研究上传进度回调