Advertisement
matro-skin

Untitled

Sep 30th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             captureImage(source) {
  2.  
  3.                 source = source || 1;
  4.  
  5.                 let cameraConfig = {
  6.                     quality: 50,
  7.                     sourceType: source,
  8.                     destinationType: navigator.camera.DestinationType.FILE_URI,
  9.                     encodingType: navigator.camera.EncodingType.JPEG,
  10.                     mediaType: navigator.camera.MediaType.PICTURE,
  11.                     cameraDirection: navigator.camera.Direction.BACK
  12.                 };
  13.  
  14.                 navigator.camera.getPicture(
  15.                     data => { this.processPicture(data) },
  16.                     error => { this.$q.notify(error) },
  17.                     cameraConfig
  18.                 )
  19.  
  20.             },
  21.  
  22.             getFileEntry (fileURL) {
  23.                 return new Promise((resolve, reject) => {
  24.                     window.resolveLocalFileSystemURL(
  25.                         fileURL,
  26.                         fileEntry => {
  27.                             resolve(fileEntry)
  28.                         },
  29.                         err => {
  30.                             reject(err)
  31.                         }
  32.                     )
  33.                 })
  34.             },
  35.  
  36.             async getFile(fileEntry) {
  37.                 try {
  38.                     return await new Promise((resolve, reject) => fileEntry.file(resolve, reject));
  39.                 } catch (err) {
  40.                     console.log(err);
  41.                 }
  42.             },
  43.  
  44.             async processPicture (path) {
  45.                 const fileEntry = await this.getFileEntry(path);
  46.                 const file = await this.getFile(fileEntry);
  47.                 this.upload(file)
  48.             },
  49.  
  50.             upload(file) {
  51.                 let data = new FormData(),
  52.                     headers = { 'Content-Type': 'multipart/form-data' };
  53.                 data.append('media', file);
  54.                 this.$axios.post(this.sendRoute, data, { headers: headers })
  55.             },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement