All Projects → silverwind → Uppie

silverwind / Uppie

Licence: bsd-2-clause
Cross-browser directory and multi-file upload library

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Uppie

React Uploady
Modern file uploading - components & hooks for React
Stars: ✭ 372 (+158.33%)
Mutual labels:  file-upload, browser
Onfido Sdk Ui
The Onfido SDK for Front-end JavaScript
Stars: ✭ 139 (-3.47%)
Mutual labels:  browser
Rxmq.js
JavaScript pub/sub library based on RxJS
Stars: ✭ 134 (-6.94%)
Mutual labels:  browser
Multicurrencywallet
Bitcoin, Ethereum, ERC20 crypto wallets with Atomic Swap exchange. Release announce: https://twitter.com/SwapOnlineTeam/status/1321844352369500160
Stars: ✭ 136 (-5.56%)
Mutual labels:  browser
Filepond
🌊 A flexible and fun JavaScript file upload library
Stars: ✭ 11,869 (+8142.36%)
Mutual labels:  file-upload
Wxread Webautoreader
微信读书自动阅读器,全自动刷阅读时长,轻轻松松冲顶霸榜,您的微读挂机好帮手
Stars: ✭ 138 (-4.17%)
Mutual labels:  browser
Fileshelter
FileShelter is a “one-click” file sharing web application
Stars: ✭ 132 (-8.33%)
Mutual labels:  file-upload
Focus Android
Firefox Focus: The privacy browser - Browse like no one’s watching.
Stars: ✭ 1,901 (+1220.14%)
Mutual labels:  browser
Keepassbrowserimporter
KeePass 2.x plugin which imports credentials from various browsers.
Stars: ✭ 139 (-3.47%)
Mutual labels:  browser
React Native Listener
A utility component to allow easy access to browser native events
Stars: ✭ 136 (-5.56%)
Mutual labels:  browser
Android Components
A collection of Android libraries to build browsers or browser-like applications.
Stars: ✭ 1,849 (+1184.03%)
Mutual labels:  browser
Otpauth
One Time Password (HOTP/TOTP) library for Node.js, Deno and browsers.
Stars: ✭ 135 (-6.25%)
Mutual labels:  browser
Surfingkeys Conf
A SurfingKeys configuration which adds 130+ key mappings for 20+ sites & OmniBar search suggestions for 50+ sites
Stars: ✭ 137 (-4.86%)
Mutual labels:  browser
Vscode Browse Lite
🚀 An embedded browser in VS Code
Stars: ✭ 134 (-6.94%)
Mutual labels:  browser
Filestack Android
Official Android SDK for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
Stars: ✭ 140 (-2.78%)
Mutual labels:  file-upload
Tenfourfox
Mozilla for Power Macintosh.
Stars: ✭ 134 (-6.94%)
Mutual labels:  browser
Angular Filemanager
JavaScript File Manager Material Design Folder Explorer Navigator Browser Manager in AngularJS with CSS3 Responsive (with FTP in PHP / Java / Node)
Stars: ✭ 1,693 (+1075.69%)
Mutual labels:  file-upload
Brotab
Control your browser's tabs from the command line
Stars: ✭ 137 (-4.86%)
Mutual labels:  browser
Europa
Pure JavaScript library for converting HTML into valid Markdown
Stars: ✭ 143 (-0.69%)
Mutual labels:  browser
Vue Image Crop Upload
A beautiful vue component for image cropping and uploading. (vue图片剪裁上传组件)
Stars: ✭ 1,892 (+1213.89%)
Mutual labels:  file-upload

uppie

Cross-browser file and directory and upload library

uppie is a tiny library (979 bytes gzipped) which helps you with file and directory uploads in browsers. It supports all current and past implementations of multi-file and directory uploads and provides you with a FormData object you can submit directly to a server through either XMLHttpRequest or fetch. Both the <input type="file"> element and drag-and-drop are supported.

Usage

npm install uppie

Alternatively, you can also include the script directly in HTML which will register window.Uppie:

<script src="uppie.min.js"></script>
<input type="file" id="file" multiple directory webkitdirectory allowdirs/>
const Uppie = require('uppie'); // when using npm module
const uppie = new Uppie();

uppie(document.querySelector('#file'), async (event, formData, files) => {
  await fetch('/upload', {method: 'POST', body: formData});
});

Browser support

files via input[file] files via DnD directories via input[file] directories via DnD
Firefox yes yes yes (50+) yes (50+)
Chrome yes yes yes (29+) yes (29+)
Edge yes yes yes (13+) yes (14+)
Safari yes yes yes (11.1+) yes (11.1+)

Notes

  • Empty directories are excluded from the results by all browsers as dictated by the spec.
  • Firefox and Safari exclude files and directories starting with a ..

API

uppie(node, [opts], callback)

  • node Node or NodeList: One or more DOM nodes. If a <input type="file"> is given, uppie will monitor it for change events. Any other element type will be enabled as a dropzone and watched for drop events. If you want to use both on the same element, use a hidden <input> and forward the click event.
  • opts Object: A options object which can contain:
    • name: The name attribute for creating the FormData entries. Default: "files[]".
  • callback Function: callback which is called every time the selected files change or when files are dropped in the dropzone.

The callback receives

  • event Event: the original event. Useful for calling event.stopPropagation().
  • formData FormData: FormData object to be used for XHR2 uploading.
  • files Array: Array of paths for preview purposes.

FormData format

name defaults to "files[]", filename will be the full path to the file, with / used as path separator. Does not include a leading slash. Make sure to sanitize filename on the server before writing it to the disk to prevent exploits involving .. in the path. Example FormData:

------Boundary
Content-Disposition: form-data; name="files[]"; filename="docs/1.txt"
Content-Type: text/plain

[DATA]
------Boundary
Content-Disposition: form-data; name="files[]"; filename="docs/path/2.txt"
Content-Type: text/plain

[DATA]
------Boundary
Content-Disposition: form-data; name="files[]"; filename="docs/path/to/3.txt"
Content-Type: text/plain

Recommended input element attributes

  • multiple: allow multiple files to be selected.
  • webkitdirectory: enable directory uploads in Chrome and Firefox.
  • allowdirs: enable experimental directory upload API in Firefox and Edge.

PHP example

Below is example for PHP 7.0 and possibly earlier versions. PHP does not parse the path from the filename field, so it is necessary to submit the path through other means, like as separate FormData fields as done in the example.

var uppie = new Uppie();
uppie(document.documentElement, function(event, formData, files) {
  files.forEach(function(path) {
    formData.append("paths[]", path);
  });

  var xhr = new XMLHttpRequest();
  xhr.open('POST', 'upload.php');
  xhr.send(formData);
});

And in upload.php:

foreach ($_FILES['files']['name'] as $i => $name) {
  if (strlen($_FILES['files']['name'][$i]) > 1) {
    $fullpath = strip_tags($_POST['paths'][$i]);
    $path = dirname($fullpath);

    if (!is_dir('uploads/'.$path)){
      mkdir('uploads/'.$path);
    }
    if (move_uploaded_file($_FILES['files']['tmp_name'][$i], 'uploads/'.$fullpath)) {
        echo '<li>'.$name.'</li>';
    }
  }
}

Note that PHP's upload limits might need to be raised depending on use case.

© silverwind, distributed under BSD licence

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].