1.0.2 • Published 4 years ago
allvalue-cdn v1.0.2
AllValue File Upload SDK
Usage
Get upload token
AllValue Api: https://apidocs.allvalue.com/oauth
AllValue Api Demo: https://admin.allvalue.com/admin/graphql-demo
mutation {
fileUploadsCreate(input:{
fileName:""
fileSize: 0
mimeType:""
resourceType:FILE
}) {
token
parameters{
name
value
}
}
}Install
npm
npm install allvalue-cdnyarn
yarn add allvalue-cdnCDN
<script src="https://su.yzcdn.cn/allvalue/open/sdk/js/upload/v1.0.0/index.js" crossorigin="anonymous"></script>API params
| 参数名 | 说明 | 是否可选 |
|---|---|---|
| file | 文件对象 | 必选 |
| token | 上传凭证 | 必选 |
| key | 文件前缀(示例:image/phone/big.png) | 必选 |
| putExtra | 额外参数 | 可选 |
const putExtra = {
fname: "qiniu.txt", // 文件名
mimeType: "text/plain", // 类型
};Upload file according media type
ES6
import { uploadImage, uploadFile } from 'allvalue-cdn'
const onImageChange = (e) => {
uploadImage(e.target.files[0], imageToken)
}
const onFileChange = (e) => {
uploadFile(e.target.files[0], fileToken)
}
<input type="file" onChange={onImageChange} accept="image/*">
<input type="file" onChange={onImageChange} accept=".doc,.docx">UMD
const onImageChange = (e) => {
allValueUpload.uploadImage(e.target.files[0], imageToken)
}
const onFileChange = (e) => {
allValueUpload.uploadFile(e.target.files[0], fileToken)
}
<input type="file" onChange={onImageChange} accept="image/*">
<input type="file" onChange={onImageChange} accept=".doc,.docx">