31 KiB
---- type: docs order: 30
title: "Generated API"
Uppy Core & Plugins
Uppy
Main Uppy core
Parameters
optsobject general options, like locales, to show modal or not to show
updateAll
Iterate on all plugins and run update on them. Called each time state changes
Parameters
state
setState
Updates state
Parameters
objectnewStatestateUpdate
getState
Returns current state
getFile
Get a file object.
Parameters
fileIDstring The ID of the file object to return.
actions
Registers listeners for all global actions, like:
file-add, file-remove, upload-progress, reset
use
Registers a plugin with Core
Parameters
PluginClass objectoptionsObject object that will be passed to Plugin lateropts
Returns Object self for chaining
getPlugin
Find one Plugin by name
Parameters
stringname descriptionname
iteratePlugins
Iterate through all used plugins
Parameters
functionmethod descriptionmethod
removePlugin
Uninstall and remove a plugin.
Parameters
instancePlugin The plugin instance to remove.
close
Uninstall all plugins and close down this Uppy instance.
info
Set info message in state.info, so that UI plugins like Informer
can display the message
Parameters
msgstring Message to be displayed by the informertypeduration
log
Logs stuff to console, only if debug is set to true. Silent in production.
Parameters
msgtype
Returns (String | Object) to log
run
Initializes actions, installs all plugins (by iterating on them and calling install), sets options
Plugin
Boilerplate that all Plugins share - and should not be used directly. It also shows which methods final plugins should implement/override, this deciding on structure.
Parameters
Returns (array | string) files or success/fail message
mount
Check if supplied target is a DOM element or an object.
If it’s an object — target is a plugin, and we search plugins
for a plugin with same name and return its target.
Parameters
Utils
src/plugins/Dashboard/index.js:14-431
Extends Plugin
Modal Dialog & Dashboard
constructor
src/generic-provider-views/index.js:43-74
Parameters
instanceobject of the pluginpluginopts
updateState
src/generic-provider-views/index.js:79-84
Little shorthand to update the state with the plugin's state
Parameters
newState
updateState
src/plugins/Webcam/index.js:107-112
Little shorthand to update the state with my new state
Parameters
newState
getFolder
src/generic-provider-views/index.js:116-137
Based on folder ID, fetch a new folder and update it to state
Parameters
idString Folder idname
Returns Promise Folders/files in folder
getNextFolder
src/generic-provider-views/index.js:144-147
Fetches new folder
Parameters
logout
src/generic-provider-views/index.js:180-194
Removes session token on client side.
Utils
A collection of small utility functions that help with dom manipulation, adding listeners, promises and other good things.
Parameters
arr
constructor
src/generic-provider-views/index.js:43-74
Parameters
instanceobject of the pluginpluginopts
updateState
src/generic-provider-views/index.js:79-84
Little shorthand to update the state with the plugin's state
Parameters
newState
updateState
src/plugins/Webcam/index.js:107-112
Little shorthand to update the state with my new state
Parameters
newState
getFolder
src/generic-provider-views/index.js:116-137
Based on folder ID, fetch a new folder and update it to state
Parameters
idString Folder idname
Returns Promise Folders/files in folder
getNextFolder
src/generic-provider-views/index.js:144-147
Fetches new folder
Parameters
logout
src/generic-provider-views/index.js:180-194
Removes session token on client side.
Utils
src/generic-provider-views/index.js:39-419
Class to easily generate generic views for plugins
This class expects the plugin using to have the following attributes
stateId {String} object key of which the plugin state is stored
This class also expects the plugin instance using it to have the following accessor methods. Each method takes the item whose property is to be accessed as a param
isFolder
Returns Boolean for if the item is a folder or not getItemData
Returns Object that is format ready for uppy upload/download getItemIcon
Returns Object html instance of the item's icon getItemSubList
Returns Array sub-items in the item. e.g a folder may contain sub-items getItemName
Returns String display friendly name of the item getMimeType
Returns String mime type of the item getItemId
Returns String unique id of the item getItemRequestPath
Returns String unique request path of the item when making calls to uppy server getItemModifiedDate
Returns object or {String} date of when last the item was modified getItemThumbnailUrl
Returns String
constructor
src/generic-provider-views/index.js:43-74
Parameters
instanceobject of the pluginpluginopts
updateState
src/generic-provider-views/index.js:79-84
Little shorthand to update the state with the plugin's state
Parameters
newState
updateState
src/plugins/Webcam/index.js:107-112
Little shorthand to update the state with my new state
Parameters
newState
getFolder
src/generic-provider-views/index.js:116-137
Based on folder ID, fetch a new folder and update it to state
Parameters
idString Folder idname
Returns Promise Folders/files in folder
getNextFolder
src/generic-provider-views/index.js:144-147
Fetches new folder
Parameters
logout
src/generic-provider-views/index.js:180-194
Removes session token on client side.
Utils
src/plugins/Webcam/index.js:14-311
Extends Plugin
Webcam
constructor
src/generic-provider-views/index.js:43-74
Parameters
instanceobject of the pluginpluginopts
updateState
src/generic-provider-views/index.js:79-84
Little shorthand to update the state with the plugin's state
Parameters
newState
updateState
src/plugins/Webcam/index.js:107-112
Little shorthand to update the state with my new state
Parameters
newState
getFolder
src/generic-provider-views/index.js:116-137
Based on folder ID, fetch a new folder and update it to state
Parameters
idString Folder idname
Returns Promise Folders/files in folder
getNextFolder
src/generic-provider-views/index.js:144-147
Fetches new folder
Parameters
logout
src/generic-provider-views/index.js:180-194
Removes session token on client side.
index
src/plugins/StatusBar/index.js:11-141
Extends Plugin
A status bar.
checkDragDropSupport
src/plugins/DragDrop/index.js:68-84
Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
Returns Boolean true if supported, false otherwise
index
src/plugins/DragDrop/index.js:11-162
Extends Plugin
Drag & Drop plugin
checkDragDropSupport
src/plugins/DragDrop/index.js:68-84
Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
Returns Boolean true if supported, false otherwise
index
src/plugins/Transloadit/index.js:8-374
Extends Plugin
Upload files to Transloadit using Tus.
checkDragDropSupport
src/plugins/DragDrop/index.js:68-84
Checks if the browser supports Drag & Drop (not supported on mobile devices, for example).
Returns Boolean true if supported, false otherwise
Dummy
Extends Plugin
Dummy A test plugin, does nothing useful
flatten
Shallow flatten nested arrays.
Parameters
arr
groupBy
Partition array by a grouping function.
Parameters
array[type] Input arraygroupingFn[type] Grouping function
Returns [type] Array of arrays
every
Tests if every array element passes predicate
Parameters
Returns bool Every element pass
toArray
Converts list into array
Parameters
list
generateFileID
Takes a fileName and turns it into fileID, by converting to lowercase, removing extra characters and adding unix timestamp
Parameters
fileNameString
runPromiseSequence
Runs an array of promise-returning functions in sequence.
Parameters
functionsargs...Any
isPreviewSupported
Takes function or class, returns its name.
Because IE doesn’t support constructor.name.
https://gist.github.com/dfkaye/6384439, http://stackoverflow.com/a/15714445
Parameters
fnObject — functionfileTypeSpecific
copyToClipboard
Copies text to clipboard by creating an almost invisible textarea, adding text there, then running execCommand('copy'). Falls back to prompt() when the easy way fails (hello, Safari!) From http://stackoverflow.com/a/30810322
Parameters
Returns Promise
isDOMElement
Check if an object is a DOM element. Duck-typing based on nodeType.
Parameters
objAny
findDOMElement
Find a DOM element.
Parameters
Returns (Node | null)
Translator
Translates strings with interpolation & pluralization support. Extensible with custom dictionaries and pluralization functions.
Borrows heavily from and inspired by Polyglot https://github.com/airbnb/polyglot.js,
basically a stripped-down version of it. Differences: pluralization functions are not hardcoded
and can be easily added among with dictionaries, nested objects are used for pluralization
as opposed to |||| delimeter
Usage example: translator.translate('files_chosen', {smart_count: 3})
Parameters
optsobject
interpolate
Takes a string with placeholder variables like %{smart_count} file selected
and replaces it with values from options {smart_count: 5}
Parameters
phrasestring that needs interpolation, with placeholdersoptionsobject with values that will be used to replace placeholders
Returns string interpolated
Meta
- license: https://github.com/airbnb/polyglot.js/blob/master/LICENSE taken from https://github.com/airbnb/polyglot.js/blob/master/lib/polyglot.js#L299
translate
Public translate method
Parameters
Returns string translated (and interpolated)
Webcam
src/uppy-base/src/plugins/Webcam.js:8-336
Webcam Plugin
init
src/uppy-base/src/plugins/Webcam.js:61-78
Checks for getUserMedia support
detectFlash
src/uppy-base/src/plugins/Webcam.js:138-162
Detects if browser supports flash Code snippet borrowed from: https://github.com/swfobject/swfobject
Returns bool flash supported
stop
src/uppy-base/src/plugins/Webcam.js:247-264
Stops the webcam capture and video playback.
getImage
src/uppy-base/src/plugins/Webcam.js:300-317
Takes a snapshot and displays it in a canvas.
Parameters
videoopts
ProgressBar
src/plugins/ProgressBar.js:8-45
Extends Plugin
Progress bar
Informer
Extends Plugin
Informer
Shows rad message bubbles
used like this: core.emit('informer', 'hello world', 'info', 5000)
or for errors: core.emit('informer', 'Error uploading img.jpg', 'error', 5000)
MetaData
Extends Plugin
Meta Data Adds metadata fields to Uppy
Tus10
Extends Plugin
Tus resumable file uploader
upload
Create a new Tus upload
Parameters
fileobject for use with uploadcurrentinteger file in a queuetotalinteger number of files in a queue
Returns Promise
Client
src/plugins/Transloadit/Client.js:4-59
A Barebones HTTP API client for Transloadit.
createAssembly
src/plugins/Transloadit/Client.js:15-48
Create a new assembly.
Parameters
getAssemblyStatus
src/plugins/Transloadit/Client.js:55-58
Get the current status for an assembly.
Parameters
urlstring The status endpoint of the assembly.
Socket
src/plugins/Transloadit/Socket.js:8-60
WebSocket status API client for Transloadit.