首页 > 其他分享 >uniapp拍照

uniapp拍照

时间:2024-05-29 14:56:04浏览次数:24  
标签:uniapp 拍照 showToast err url res file uni

 plus.camera.getCamera().captureImage(function (e) {
        plus.io.resolveLocalFileSystemURL(
          e,
          function (entry) {
            entry.file(function (file) {
              const url1 = entry.toLocalURL();
              uni.uploadFile({
                name: "file",
                url: "/file/uploadFile",
                filePath: url1,
                success: (res_two) => {
                  const url = JSON.parse(res_two.data).data.url;
                  that.leaveImg = url;

                  if (notify) {
                    uni.showToast({ title: "图片上传成功,可进行离场操作", icon: "none" });
                  }
                },
                fail: (err) => uni.showToast({ title: err, icon: "error" }),
              });
            });
          },
          function (e) {
            console.log("读取拍照文件错误:" + e.message);
          }
        );
      });

  

uni.chooseImage({
        count: 1, //默认9
        sizeType: ["original", "compressed"],
        sourceType: ["camera"],
        success: async (res_one) => {
          uni.uploadFile({
            name: "file",
            url: "/file/uploadFile",
            filePath: res_one.tempFilePaths[0],
            success: (res_two) => {
              const url = JSON.parse(res_two.data).data.url;
              this.leaveImg = url;

              if (notify) {
                uni.showToast({ title: "图片上传成功,可进行离场操作", icon: "none" });
              }
            },
            fail: (err) => uni.showToast({ title: err, icon: "error" }),
          });
        },
        fail: (err) => {
          console.log("失败" + err);
        },
        complete: (err) => {
          console.log("完成" + err);
        },
      });

  

翻译

搜索

复制

标签:uniapp,拍照,showToast,err,url,res,file,uni
From: https://www.cnblogs.com/zoushuangyu/p/18220290

相关文章