Nativescript:无法解析存储Uri

时间:2017-05-24 18:04:38

标签: firebase nativescript firebase-storage angular2-nativescript

我正在使用Nativescript构建应用程序,而我几乎是新手。我正在尝试使用firebase上传图像,并使用插件nativescript-imagepicker。

一旦我拥有了我想要的图像,那么我必须将其上传到Firebase,但是当我这样做时,我收到以下错误:  无法解析存储Uri

这是我的代码。看到我首先调用函数selectImages从我的设备中选择我想要的图像,然后为每一个我调用函数uploadFile,但这里是我有错误的地方。

onSelectMultipleTap() {
    // console.log('Im in');



    function selectImages() {
        var context = imagepicker.create({
            mode: "multiple"
        });

        context
            .authorize()
            .then(function() {
                return context.present();
            })
            .then(function(selection) {

                selection.forEach(function(selected) {

                    uploadFile(selected);

                });
            }).catch(function (e) {
                console.log(e);
            }); 
    }

    function uploadFile(file) {

        // init the file-system module
        var fs = require("file-system");

        // grab a reference to the app folder
        var appPath = fs.knownFolders.currentApp().path;

        // determine the path to a file in the app/res folder
        var logoPath = appPath + "/res/telerik-logo.png";            

        // now upload the file with either of the options below:
        firebase.uploadFile({

            // optional, can also be passed during init() as 'storageBucket' param so we can cache it (find it in the Firebase console)

            bucket: 'mystory-2.appspot.com',
            // the full path of the file in your Firebase storage (folders will be created)

            remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',
            // option 1: a file-system module File object
            localFile: fs.File.fromPath(logoPath),

            // option 2: a full file path (ignored if 'localFile' is set)
            localFullPath: logoPath,

            // get notified of file upload progress
            onProgress: function(status) {
            console.log("Uploaded fraction: " + status.fractionCompleted);
            console.log("Percentage complete: " + status.percentageCompleted);
            }
        }).then(
            function (uploadedFile) {
                console.log("File uploaded: " + JSON.stringify(uploadedFile));
            },
            function (error) {
                console.log("File upload error: " + error);
            }
        );

    }


    selectImages()

}   

谢谢! :)

0 个答案:

没有答案