阿西河

所有教程

公众号
🌙
阿西河前端的公众号

我的收藏

    最近访问  (文章)

      教程列表

      抓包专区
      测试专区

      插件 jQuery.lite uploader.js 中文API文档

      插件 jQuery.lite uploader.js 中文API文档 https://github.com/burt202/lite-uploader

      LiteUploader

      npmlicenseBuild Status

      Examples | Changelog

      This is a lightweight library for NodeJS and jQuery, aiming to make uploading files a doddle. With some useful options including basic validation, it is a good choice for any developer who is not so worried about supporting legacy browsers.

      Features

      • dependency free
      • file type and size validation
      • support for custom validators
      • hooks for all major events like progress, success, fail etc
      • drag/drop support
      • ability dynamically update the form data packet before each upload
      • upload multiple files as individual requests

      NodeJS

      npm install lite-uploader --save

      Browser

      <script src="./src/liteuploader.js"></script>

      jQuery is supported but is optional

      Options

      NameTypeDefaultDescription
      urlString or Function (required)nullurl that will handle the upload, or a function that resolves with the url
      refString (required)nullthe request argument name for the file form data. Will fallback to the name property of the file input field if not supplied.
      methodStringPOSTallows overriding of the default HTTP request method if necessary
      rulesObject{}object where you can specify validation rules for the files to be uploaded - current supported rules are:
      • allowedFileTypes (list of comma-separated mime-types, wildcards such as image/* are also supported)
      • maxSize (in bytes)
      paramsObject{}object of params to be sent to the server in addition to the files being uploaded
      headersObject{}object of headers to be sent to the server
      validatorsArray[]an array of functions that can take a File and return a validation result on it, see examples for usage
      singleFileUploadsBooleanfalseset to true to upload each file of a selection using an individual request
      withCredentialsBooleanfalseindicates whether requests should be made using credentials such as cookies
      beforeRequestFunctionnulldelay the file upload request by returning a promise. Recieves the Files and the FormData. Expected to resolve with the FormData to continue. Reject to stop upload.
      sendAsFormDataBooleantruewhen set to false and singleFileUploads is true, dont send the file payload as form data. Also any params added via 'addParam' to form data, will be ignored

      Events

      NameParametersDescription
      lu:errorseventName, {errors}triggered when errors are found, including built-in and custom validators - see 'Error Types' section for more
      lu:starteventName, {files}triggered before any uploading starts
      lu:finisheventNametriggered when all uploading has finished
      lu:beforeeventName, {files}triggered before each request to the server
      lu:progresseventName, {files, percentage}triggered whilst uploading files
      lu:successeventName, {files, response}triggered on a successful request to the server
      lu:faileventName, {xhr}triggered on a failed request to the server
      lu:cancelledeventNametriggered on upload abort

      Error Types

      Below is an overview of the built-in error types that can be returned when validating files

      • type - when file mime type does not match any mime types supplied in the rule.allowedFileTypes option
      • size - when file size is above the size (in bytes) supplied in the rule.maxSize option
      • refRequired - when there is no name attribute on the file input and no ‘ref’ options is passed to the plugin
      • urlRequired - when no ‘url’ option is passed to the plugin

      Public API

      startUpload(files)

      Starts the upload

      NameTypeDefaultDescription
      filesFileList (optional)nulla list of files to be uploaded, takes priority over default mechanism if supplied

      addParam(key, value)

      Allows parameters to be added after plugin instantiation

      NameTypeDefaultDescription
      keyString (required)n/aname of parameter to be added
      valueString (required)n/avalue of parameter to be added

      cancelUpload()

      Allows the upload to be cancelled, triggers lu:cancelled

      NameTypeDefaultDescription
      No parameters

      Browser Support

      • Chrome 45+
      • Firefox 34+
      • Edge 12+
      • Internet Explorer NO (because Promises and Object.assign are used)
      • Safari 9+
      • Opera 32+

      License

      Licensed under the MIT License.

      View the full license here.

      目录
      目录