GithubHelp home page GithubHelp logo

wx-multipart's Introduction

Summary

小程序官方提供的api wx.uploadFile一次只能上传一个文件,Multipart实现了一般的表单上传,无文件数量限制

Usage

  1. 直接传递给构造函数
const Multipart=require('wx-multipart') //小程序中使用可以直接复制dist目录下的Multipart.min.js文件
const fields=[{
  name:'username',
  value:'小黄'
},{
  name:'number',
  value:'13812345678'
}]
const files=[{
  filePath:'http://example.png'
}]
new Multipart({
  fields,
  files
}).submit('http://localhost:3000/upload')
  1. 单个字段和文件添加
const Multipart=require('wx-multipart')
let m=new Multipart({files:[], fields:[]})
m.field({
  name:'username',
  value:'小黄'
})
m.file({
  filePath:'http://example.png'
})
m.file({
  filePath:'http://example2.png'
})
m.submit('http://localhost:3000/upload')

detail

Syntax

new Multipart(config)

Multipart Instances

Methods

  • Multipart.prototype.field(field)
    增加表单字段
  • Multipart.prototype.file(file)
    增加文件
  • Multipart.prototype.submit(url)
    上传表单

Demo

examples文件夹下有两个目录

  • backend
    后端
  • wx_demo
    小程序
  1. 运行后端
npm i
npm run build 
npm run test
  1. 测试小程序 用微信开发者工具打开wx_demo,提交表单后,上传的文件保存在./examples/tempFiles

wx-multipart's People

Contributors

supperchong avatar fancylou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.