日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ionic html5 上传图片,ionic4+angular7+cordova上传图片功能的实例代码

發布時間:2025/3/11 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ionic html5 上传图片,ionic4+angular7+cordova上传图片功能的实例代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言

ionic是一個垮平臺開發框架,可通過web技術開發出多平臺的應用。但只建議開發簡單應用。復雜的應用需要用到許多cordova插件,而cordova插件的更新或者移動平臺的更新很可能導致插件的不可用,維護升級成本較高。

安裝插件

安裝插件Image Picker

$ ionic cordova plugin add cordova-plugin-telerik-imagepicker

$ npm install @ionic-native/image-picker

安裝插件File Transfer

$ ionic cordova plugin add cordova-plugin-file-transfer

$ npm install @ionic-native/file-transfer

添加到app.module.ts

import { ImagePicker } from '@ionic-native/image-picker/ngx';

import { FileTransfer} from '@ionic-native/file-transfer/ngx';

html添加控件

上傳圖片

編輯ts文件

export class UploadPage {

constructor(

private imagePicker: ImagePicker,

private transfer: FileTransfer

) {

}

// 選擇圖片,選擇完成立即上傳

chooseImage() {

const options = {

maximumImagesCount: 1

// width: int,

// height: int,

// quality: int (0-100),

// outputType: int

};

this.imagePicker.getPictures(options).then((results) => {

for (const res of results) {

this.upload(res);

}

}, (err) => {

});

}

// 上傳文件

upload(file) {

const fileTransfer: FileTransferObject = this.transfer.create();

const options: FileUploadOptions = {

fileKey: 'file',

fileName: timestamp() + '.jpg',

params: {

type: 'file',

action: 'upload',

timestamp: timestamp(),

auth_token: '79e1bd1504962034c068461d58b9cd89a1d8a4a1'

},

headers: {}

};

fileTransfer.upload(file, 'https://imgbb.com', options)

.then((data) => {

alert('success');

})

.catch((e) => {

});

}

}

最終效果

總結

以上所述是小編給大家介紹的ionic4+angular7+cordova上傳圖片功能的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

總結

以上是生活随笔為你收集整理的ionic html5 上传图片,ionic4+angular7+cordova上传图片功能的实例代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。