簡體   English   中英

空的 base64 字符串

[英]Empty base64 string

我的 Instagram 插件和 Cordova 的 base64 插件有問題。

我正在嘗試的是:我想通過 Instagram(最好是 Story)分享一張圖片。

我有這樣的絕對路徑: '/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

提前致謝!

好的,所以我找到了解決方案。 安裝在設備上的應用程序無法訪問存儲我的圖像的資產文件夾。

我必須將文件復制到應用程序的數據目錄才能進一步使用它。

代碼如下所示:

private basedirectory = 'www/assets/images/storyTemplates/';
socialShare(filename){
 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

好的哇。 我討厭我的生活。 我已經調試這段代碼一段時間了,看起來this.file是一個字符串。 雖然我將其聲明為private file: File; 在 ionViewWillEnter 的這個組件中,我得到一個名為“file”的 navParam。 並且console.log(this.file)顯然會打印出名為“file”的 navParam 中的內容。

不得不重命名 navParam 並且它有效......不知道這是否有意義:D

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM