从媒体库Ionic上传图片和视频

时间:2018-03-13 07:31:37

标签: video ionic-framework ionic3 cordova-plugins cordova-media-plugin

我想使用cordova-media-plugin上传图片和视频,现在我只能使用此代码上传图片:

let camOptions: CameraOptions = {
  quality: 80,
  sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
  destinationType: this.camera.DestinationType.FILE_URI,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE,
  allowEdit: true,
  targetWidth: 1080,
  targetHeight: 1080,
  correctOrientation: true,
  saveToPhotoAlbum: false
}       

this.cameraIsCaptureImage(camOptions)

cameraIsCaptureImage(options: CameraOptions){
this.camera.getPicture(options).then(image => {
  this.file.resolveLocalFilesystemUrl(image).then(fileEntry => {
    this.uploadImage(fileEntry).then(file => {
      this.tabs.select(0)
      const story = {type: 'image'}
      this.home.push(StoryFormPage, {file, story})
      this.loading.dismiss()
    })
  })
}, (err) => {
  console.log(err)
  this.loading.dismiss()
});
}

uploadImage(fileEntry){
    let options: FileUploadOptions = {
      fileKey: 'file',
      fileName: fileEntry.name,
      mimeType: "image/jpeg",
      chunkedMode: false,
      headers: {
        Connection: "close"
      }
    }

    return this.services.uploadFile(fileEntry.toURL(), options)
  }

我希望只能从媒体库中选择图片或视频并上传,视频格式应为mp4

0 个答案:

没有答案