簡體   English   中英

Cordova:從內容Uri獲取文件Uri

[英]Cordova: Getting a file Uri from a content Uri

我使用Apache Cordova實現了一個應用程序,並使用了$ cordovaCamera插件。 當$ cordovaCamera的源類型為Camera.PictureSourceType.PHOTOLIBRARY時,輸出類似於

“內容://com.android.providers.media.documents/document/image”

當我使用Camera.PictureSourceType.CAMERA時

“文件:///storage/emulated/0/Android/data/com.ionic.viewapp/cache/image.jpg”。

在我的情況下,格式“ file:// ..”更有用。

是否可以從內容URI獲取文件URI?

我找到了許多關於這個問題的答案,但是所有解決方案都是針對JAVA而不是Javascript。

我發現了問題。 我正在使用Ionic和Ionic View在設備中進行測試。

當我嘗試cordova-plugin-filepath時,它不起作用。 但是我發現問題是在Ionic View中此插件失敗。

因此,我在服務中編寫了此功能:

// data is the return of $cordovaCamera.getPicture.

    getFilePath: function(data){ 
             var deferred = $q.defer();
             window.FilePath.resolveNativePath(data, function(result) {
                    deferred.resolve('file://' + result;);
                  }, function (error) {
                      throw new Error("");
                  });

             return deferred.promise;
         }

返回我需要的文件URI。 然后,我將apk安裝在手機中,並且可以正常工作。 現在,我可以存儲從相機或畫廊獲得的圖像,然后上傳到服務器。

上面的答案有誤。

window.FilePath.resolveNativePath成功之后,其結果已經具有格式: file:///... ,因此無需在file://

暫無
暫無

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

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