Skip to content

uppy

安装

$ npm install @uppy/core

从 CDN 加载。

<!-- 1. Add CSS to `<head>` -->  
<link href="https://releases.transloadit.com/uppy/v4.13.3/uppy.min.css" rel="stylesheet">  

<!-- 2. Initialize -->  
<div id="uppy"></div>  

<script type="module">  
import { Uppy } from "https://releases.transloadit.com/uppy/v4.13.3/uppy.min.mjs"  
const uppy = new Uppy()  
</script>

用法

API: https://uppy.io/docs/uppy/

import Uppy from '@uppy/core';  

const uppy = new Uppy();

使用插件

import Uppy from '@uppy/core';  
import DragDrop from '@uppy/drag-drop';  

const uppy = new Uppy();  
uppy.use(DragDrop, { target: 'body' });

addFile()

uppy.addFile({  
name: 'my-file.jpg', // file name  
type: 'image/jpeg', // file type  
data: blob, // file blob  
meta: {  
// optional, store the directory path of a file so Uppy can tell identical files in different directories apart.  
relativePath: webkitFileSystemEntry.relativePath,  
},  
source: 'Local', // optional, determines the source of the file, for example, Instagram.  
isRemote: false, // optional, set to true if actual file is not in the browser, but on some remote server, for example,  
// when using companion in combination with Instagram.  
});

upload()

uppy.upload().then((result) => {  
  console.info('Successful uploads:', result.successful);  

  if (result.failed.length > 0) {  
    console.error('Errors:');  
    result.failed.forEach((file) => {  
      console.error(file.error);  
    });  
  }  
});