cordova upload pictures, upload video (uploaded more pictures, more video)

1. Download plugin (need to download)

cordova plugin add cordova-plugin-imagepicker (this plugin select the picture more beautiful, and can only get the picture)

cordova plugin add cordova-plugin-camera (get a single video, single picture)

cordova plugin add cordova-plugin-media-capture (acquisition of audio, video, pictures)

2. Upload an array of multiple pictures or video (video images can be placed in the same array)

var arr = []

3.cordova plugin add cordova-plugin-imagepicker

ImagePicker.getPictures ((RES) => { 
     res.images.forEach ((Val) => {
            // stuffed array 
          imArr.push (val.uri) 
    }) 
}, (ERR) => {the console.log ( ERR)}, 
{ 
    // configure 
    quality: 80, // picture quality 
    maximumImagesCount:. 9   // limit the number of uploaded 
} 
}

cordova plugin add cordova-plugin-media-capture

navgator.device.capture.captureVideo(
      (mediaFiles) => {
           console.log(mediaFile[0])
           imgArr.push(mediaFile[0].localURL)
      },
      (err)=>{console.log(err)},
      options
)
options = {
     limit: 2,
     duration
}

cordova plugin add cordova-plugin-camera Look upload a single picture

4. Batch Upload (upload will imgArr)

In addition cordova plugin add cordova-plugin-camera plug-in, the other two will be installed by default Cordova-plugin-file

He will change the js file attribute, so you want him to come back here, you can, with its own interface by uploading formdata

FormData new new FormData = var () 
var = 0 loopNum
imgArr.forEach ((Val, index) => {
Method // cordova-plugin-file widget resolveLocalFileSystemURL (Val, (FileEntry)
=> {
// Get file object, and js file is not the same fileEntry.file ((file)
=> {
// read
var Reader = new new the FileReader () reader.onloadend = E => {
              // Blob format into const the_file
= new new Blob ([e.target .Result], {type: file.type})
              // stored to formdata.append (
'Image' + (index + 1 ), the_file, file.name)
              // prevent onloadend event does not execute the order loopNum
++ IF (loopNumm === imgArr.length) {
// function is triggered requestImgs interface functions, write your own the formdata pass into the requestImgs (formdata) } }
          // trigger onloadend event reader.readAsArrayBuffer (File) }) })

 

Guess you like

Origin www.cnblogs.com/guan-shan/p/11580478.html