uniapp calls the camera and takes pictures, and sends the pictures to the backend

 To open the camera in the Android app project written by uniapp, you must first check this option in the manifest.json:

 After changing the configuration, you need to re-make the custom base to run, how to make a custom base is in this link:

How does uniapp create an Android app project, make a custom debugging base, and run it successfully

Call the camera and take a photo, and send the photo to the backend:


		methods: {
			catchPhoto() {
                //要保留一下this,不然在其他方法内部拿不到data里的数据
				let that = this;
				plus.camera.getCamera().captureImage(function(e) {
					plus.io.resolveLocalFileSystemURL(e, function(entry) {
						entry.file(function(file) {
							that.img = entry.toLocalURL() //图片的本地路径
							that.imgfile = file.name //图片的文件名
                            //上传文件到接口
							uni.uploadFile({
								url: 'http://xxxxxx',//要上传的地址
								filePath: that.img,//图片的本地路径
								name: that.imgfile,//图片的文件名
								success: (res) => { //成功的回调
									console.log(res);
								},
							})
						})
					}, function(e) {
						console.log("读取拍照文件错误:" + e.message);
					});
				})
			}
		}

Guess you like

Origin blog.csdn.net/qq_68155756/article/details/130324434