空base64字符串

问题描述 投票:0回答:1

我的Instagram插件和Cordova的base64插件都有问题。

我正在尝试的是:我想通过Instagram分享图片(最好是故事)。

我具有这样的绝对路径:'/assets/images/storyTemplates/diary.png'

现在,文档说,我要做的就是这样:

this.base64.encodeFile(path).then((base64File: string) => {
   console.log('nativepath: ' + path);
   console.log('base64: ' + base64File);
   if (this.instagram.isInstalled()) {
      this.instagram.share('data:image/png;base64,file://' + base64File, 'caption').then(data => {
            if (data) {
              console.log(data);
            }
          });
        }
      });

但是console.log(base64File)为空...错误输出:

nativepath: /assets/images/storyTemplates/diary.png
base64: 
copying caption:  caption

vendor.js:45196 ERROR Error: Uncaught (in promise): Share Cancelled
    at resolvePromise (polyfills.js:4086)
    at resolvePromise (polyfills.js:4043)
    at polyfills.js:4147
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:3657)
    at Object.onInvokeTask (vendor.js:64580)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:3656)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:3429)
    at drainMicroTaskQueue (polyfills.js:3835)

我必须在配置文件中导入一些XML吗?或在AndroidManifest中?

我现在真的很无助:D

谢谢!

angular cordova base64 instagram ionic4
1个回答
0
投票

好,所以我找到了解决方案。安装在设备上的应用程序无法访问存储我的图像的资产文件夹。

我必须将文件复制到应用程序的数据目录中才能进一步使用它。

代码看起来像这样:

 this.file.copyFile(this.file.applicationDirectory + this.basedirectory, filename, this.file.dataDirectory, filename).then(() => {
      this.file.checkFile(this.file.dataDirectory, filename).then(result => {
        this.file.readAsDataURL(this.file.dataDirectory, filename).then(base64file => {
          console.log('encoded: ' + base64file);
          if (this.instagram.isInstalled()) {
            this.instagram.share('data:image/png;base64,file:///' + base64file, 'pferdesporthaus_loesdau').then(instagramData => {
              if (instagramData) {
                console.log(instagramData);
              }
            });
          }
        });
      }, (error) => {
        console.log('checkFile Error');
        console.log(error);
      });
    }).catch(err => {
      console.log('copying error');
      console.log(err);
    });

我希望你能得到答案,我在解释:D方面很糟糕

© www.soinside.com 2019 - 2024. All rights reserved.