Package Exports
- uploady
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (uploady) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
uploady
Utilities for the file upload process (primarily photos) as it relates to Prospector and the WHCC system.
Install
npm install --save uploady prospector-js-sdk superagentUsage
Table of Contents
- Uploady
- UploadyConfig
- UploadPhotosConfig
- UploadPhotoConfigObject
- EVENTS
- HOME
- UploadyFileExifListener
- UploadyProgressListener
- UploadyCompleteListener
- UploadyFileProgressListener
- UploadyFileErrorListener
- UploadyFileInvalidListener
- UploadyFileSuccessListener
- UploadyUploadPhotosResult
- getUploadPhotosConfig
Uploady
Uploady upload manager.
Parameters
configUploadyConfig
Examples
Using event listeners.
import Uploady, { EVENTS, HOME } from 'uploady'
const uploady = new Uploady({
home: HOME.PROJECT,
homeId: 'foo-project-id',
prospectorBaseUrl: 'https://prospector-url/api/v1',
prospectorToken: someProspectorToken
})
uploady.addEventListener(EVENTS.FILE_PROGRESS, (file, id, progress) => {
console.log(`${file.name} (${id}) progress: ${progress}`)
})
uploady.addEventListener(EVENTS.FILE_SUCCESS, (file, id) => {
console.log(`${file.name} (${id}) success!`)
})
uploady.addEventListener(EVENTS.FILE_ERROR, (file, id, err) => {
console.error(`${file.name} (${id}) error: ${err}`)
})
uploady.addEventListener(EVENTS.PROGRESS, progress => {
console.log(`Overall Uploady progress: ${progress}`)
})
uploady.addEventListener(EVENTS.COMPLETE, () => {
console.log('Uploady complete!')
})
uploady.uploadPhotos(someFileList)Using async/await.
import Uploady, { HOME } from 'uploady'
const uploady = new Uploady({
home: HOME.EDITOR,
homeId: 'foo-editor-id',
prospectorBaseUrl: 'https://prospector-url/api/v1',
prospectorToken: someProspectorToken
})
// You can still attach event listeners if you like.
// Don't need a `try`/`catch` because this `Promise` should
// always resolve.
const results = await uploady.uploadPhotos(someFileList)
console.log('Uploady complete', results)
results.forEach(results, ({ url, error }) => {
if (error) console.error(`Upload failed for ${url}`, error)
})Using upload photos config
// If you need to know the ID of the entities returned from Prospector when
// the file is given a home, you can process your FileList into a config
// that you can inspect before handing off to Uploady.
import Uploady, { getUploadPhotosConfig } from 'uploady'
const uploadPhotosConfig = getUploadPhotosConfig(someFileList)
// Inspect those IDs.
for (const [file, { id }] of uploadPhotosConfig) {
console.log(`The ID of ${file.name} is ${id}`)
}
// Then hand the config off to Uploady.
const results = await uploady.uploadPhotos(uploadPhotosConfig)
// ...allowedMimeTypes
home
Type: HOME
homeId
Type: string
loadExif
Type: boolean
progress
A ratio 0-1 of the overall progress of the current batch of uploads.
Type: number
prospectorToken
Sets the prospector token currently in use by Uploady.
Parameters
token
uploadPhoto
Uploads a single photo.
Parameters
photoFileconfigUploadPhotoConfigObjectThrows Error if no
photowas provided.
Returns Promise<File>
uploadPhotos
Uploads a batch of photos.
Parameters
photos(FileList | UploadPhotosConfig) See getUploadPhotosConfig.Throws Error if
photosis empty or not provided.
Returns Promise<Array<UploadyUploadPhotosResult>> Resolves when all
photos are done being processed – regardless of whether or not they
succeeded. This Promise does not reject.
_fileExifListener
Parameters
UploadyConfig
Type: Object
Properties
homeHOME? Default value:HOME.PROJECT.homeIdstring ID of the resource that the files will call home – project, editor, account, etc.loadExifboolean? Default value:true.prospectorBaseUrlstring? Required ifprospector-js-sdkis not already configured.prospectorTokenstring Token to use in communication withprospector.
UploadPhotosConfig
Type: Map<File, UploadPhotoConfigObject>
UploadPhotoConfigObject
Type: Object
Properties
idstring ID of the photo. Should be unique.
EVENTS
Events dispatched to instances of Uploady. To listen to a particular event,
call addEventListener.
Type: string
EXIF_LOADED
Dispatched when exif data is available for a file. See UploadyFileExifListener
FILE_INVALID
Dispatched when an individual file is of an invalid type. See UploadyFileInvalidListener
FILE_PROGRESS
Dispatched for progress events for individual files being processed. See UploadyFileProgressListener for the listener contract.
FILE_SUCCESS
Dispatched when an individual file has been successfully processed. See UploadyFileSuccessListener for the listener contract.
FILE_ERROR
Dispatched when an individual file encounters an error during processing. See UploadyFileErrorListener for the listener contract.
PROGRESS
Dispatched whenever a finishes processing – regardless of whether or not that processing was successful. See UploadyProgressListener for the listener contract.
COMPLETE
Dispatched when processing of all files is complete – regardless of whether or not they were successful. See UploadyCompleteListener for the listener contract.
HOME
Enum to represent the types of "homes" in which photos will be added.
Type: string
ACCOUNT
(NOT YET SUPPORTED) The resource will be added to an account.
EDITOR
The resource will be added to an editor.
PROJECT
The resource will be added to a project.
Default set of valid upload types (for photos).
UploadyFileExifListener
Type: Function
Parameters
UploadyProgressListener
Type: Function
Parameters
progressnumber 0-1 ratio.
UploadyCompleteListener
Type: Function
UploadyFileProgressListener
Type: Function
Parameters
UploadyFileErrorListener
Type: Function
Parameters
UploadyFileInvalidListener
Type: Function
Parameters
fileFileidstring Unique ID of the entity from Prospector.
UploadyFileSuccessListener
Type: Function
Parameters
fileFileidstring Unique ID of the entity from Prospector.entityObject Object returned from Prospector when the file is added to its home.
UploadyUploadPhotosResult
Type: Object
Properties
fileFile The respective photo'sFile.errorError? If the photo failed to upload, theErroris returned here.
getUploadPhotosConfig
Associates a list of files with respective UUIDs.
Parameters
filesFileList
Returns UploadPhotosConfig