uni-app icon indicating copy to clipboard operation
uni-app copied to clipboard

uniapp app端获取不到图片信息(拍摄时间,经纬度等)

Open yaoleyaotou111 opened this issue 1 year ago • 2 comments

问题描述 uniapp app端,想在获取图片的时候获取图片信息(如拍摄时间,经纬度等),但在app端使用getImageInfo与exif插件都无法获取到

复现步骤 用uniapp写的app端获取不到图片信息,用exif插件也不行,代码如下

infoImgZip(paths) {
          let that = this,
              dateTime = "";
          // #ifdef APP-PLUS
          let tempImg = paths;
          // 读取本地文件
          plus.io.resolveLocalFileSystemURL(tempImg, function (entry) {
              if (plus.os.name === "Android" && (plus.os.version > 10)) {
                  // andorid10以上把公共目录下的图片复制到应用沙盒目录下,由于要使用原图,只能使用copyTo,读取完内容后remove掉文件,否则会造成相册中多出图片内容
                  plus.io.resolveLocalFileSystemURL('_doc', function (root) {
                      let imgNameArr = tempImg.split("/");
                      let extArr = imgNameArr[imgNameArr.length - 1].split(".");
                      let imgName =
                          `${Date.parse(new Date())}.${extArr[extArr.length - 1]}`; // 文件名称由于相同名称的文件无法copy成功,故文件名称使用时间戳+原图片扩展名
                      entry.copyTo(root, imgName, function (entry2) {
                          entry2.file(
                              function (file) {
                                //   console.log('file', file);
                                  var reader = new plus.io.FileReader();
                                  reader.onloadend = function (e) {
                                    //   console.log('reader');
                                      var base64 = e.target.result;
                                      var name = tempImg.substring(tempImg.lastIndexOf("/") + 1);
                                      var img = {
                                          path: tempImg,
                                          name: name,
                                          src: base64,
                                      };
                                      EXIF.getData(img, function () {
                                          dateTime = EXIF.getTag(this, "DateTimeOriginal");
                                          console.log('dateTime', dateTime);
                                      });
                                  };
                                  reader.readAsDataURL(file);
                              },
                              function (e) {
                                  console.log("读写出现异常: " + e.message);
                                  throw "Could not load image";
                              }
                          );
                      }, function (e) {
                          alert(e.message);
                      });
                      // remove掉copy的图片 解决拍摄得无法上传问题
                      if (paths.startsWith("file://")) {
                          entry.remove(function (entry) {
                              console.log("Remove succeeded");
                          }, function (e) {
                              alert(e.message);
                          });
                      }
                  })
              } else {
                  // android10及以下以及iOS依然使用原先的读取方式
                  entry.file(
                      function (file) {
                          var reader = new plus.io.FileReader();
                          reader.onloadend = function (e) {
                              var base64 = e.target.result;
                              //console.log("base64",base64);
                              var name = tempImg.substring(tempImg.lastIndexOf("/") + 1);
                              var img = {
                                  path: tempImg,
                                  name: name,
                                  src: that.filterBase64(base64),
                              };
                              EXIF.getData(img, function () {
                                  dateTime = EXIF.getTag(this, "DateTimeOriginal");
                                  let tagj = EXIF.getTag(this, "GPSLongitude");
										let tagw = EXIF.getTag(this, "GPSLatitude");
                                  console.log('dateTime', dateTime);

                              });
                          };
                          reader.readAsDataURL(file);
                      },
                      function (e) {
                          console.log("读写出现异常: " + e.message);
                          throw "Could not load image";
                      }
                  );
              }

          });
          // #endif
      },

预期结果 uniapp app端能获取到图片的信息,如拍摄时间(经纬度能获取到就更好)

实际结果 原生的uni.getImageInfo在app端获取不到图片信息,h5是可以,有file对象lastModified。然后用exifjs插件,安卓10及以下和ios也获取不了图片信息

系统信息: 如用上述exif代码,安卓10以上图片有信息,没问题。但ios及安卓10及以下的不可以。

补充信息

yaoleyaotou111 avatar Jan 26 '24 02:01 yaoleyaotou111

你提到 uni. getImageInfo 不能获取到图片信息,是指什么信息,文档提到了返回的具体数据类型 https://uniapp.dcloud.net.cn/api/media/image.html#getimageinfo

你提到的 exif 插件,不属于 uni-app 本身提供的功能,可以去对应的插件下获取帮助。

Otto-J avatar Jan 26 '24 11:01 Otto-J

的插件下获取帮助。

我表达有误,本意是想借问getImageInfo的问题。h5端的话,用getImageInfo的话,虽然文档中没有这个返参,但可能是网页原因他会有图片的拍摄(修改)时间字段(lastmodified),app端的话用getImageInfo是没有这些字段,所以我借助相关js库来解决;但相关js库在app端也无法获取到图片的拍摄时间。所以想问下这个有uniapp app端的解决方案吗

yaoleyaotou111 avatar Jan 27 '24 01:01 yaoleyaotou111