2.0.6 • Published 3 years ago
scan-package-v2 v2.0.6
Brandactif scan package
Getting Started
Those are the instructions on how to use the library:
Prerequisites
apiKey
- to get access to our api you need to include a key generated by our administrator. To get it, contact us:apiUrl
- to get access to our api you need to include a key generated by our administrator. To get it, contact us:npm
oryarn
- dependency management
Installing
npm:
npm install scan-package-v2
yarn:
yarn add scan-package-v2
Usage
The library accepts arguments:
Name | Type | Required | Description |
---|---|---|---|
apiKey | string | Required | access key, to get access contact us |
apiUrl | string | Required | api url, to get access contact us |
file | File image/* | Required | File from onChange event accepts all types of image |
options | object | Optional | See below |
options object:
{
coords: { //GPS location, it helps us
long, //longitude from navigator
lat, //latitude from navigator
},
deviceId: "", //id of device
userId: "", //unique ID for PVS campaign
uuid: "", //unique uuid for personal experience campaign
previewHandler: (base64) => { //callback that returns base64 of image you scan
//... Your code here
},
progressHandler: (progress) => { //callback that returns progress of uploading an image - 0 - 100
//... Your code here
},
fetchTimer: //the number of repetitions of fetching redirect_url
}
To use that package you need to import it first:
import scanPackage from 'scan-package-v2'
Then you can use it on an input type file onChange function:
const options = {
coords: {
long: -115.80666344,
lat: 37.234332396,
},
deviceId: "test_deviceId",
userId: "test_user",
uuid: "test_uuid",
previewHandler: preview => {
console.log(preview) //base64 of uploaded image
}
}
const handleChange = ({ target: { files } }) => {
const file = files[0]
if (!file) {
throw new Error('File is required')
}
scanPackage(apiKey, apiUrl, file, options)
.then(response => console.log(response))
.catch(error => console.log(error.message))
}
<input accept="image/*" onChange={handleChange} type="file" />
Built with
- JavaScript Load Image - The library for resizing / rotating and downsizing images
- Platform - The library that takes data about device like os, os version, browser etc.