не может создать загружаемую ссылку из хранилища Firebase - PullRequest
0 голосов
/ 10 апреля 2019

Я занимаюсь разработкой собственного приложения React. Я загружаю серию изображений с помощью response-native-image-crop-picker. Используя способ хранения пути в массиве и поочередно загружая изображение. но я не могу создать загружаемую ссылку для загруженных файлов. Я получаю 2 ошибки

1) Невозможно прочитать свойство 'then' из неопределенного
2) при попытке получить скачиваемую ссылку не может найти объект

ниже мой код

            AddProduct = () => {
                this.setState({ loading: true })
                this.setState({ disabled: true })
                //-------------UUIDGenerator-------------

                UUIDGenerator.getRandomUUID().then((productUid) => {
                this.setState({ productUid });
                () => console.log("setted state=" + this.state.productUid)
                console.log("Generated UUid " + this.state.productUid)
                });
                //----------------------------------------
                //image upload
                try {

                setTimeout(() => {
                    const fs = RNFetchBlob.fs
                    const uid = "flyers/" + this.state.productUid;
                    const imageRef = firebase.storage().ref(uid).child('abc' + ".jpg") //string "dp1.jpg"
                    let mime = 'image/jpg'

                    if (this.state.imagePath === "") {
                    alert("Select a Flyer")
                    return
                    }
                    //-----------------Checking Inputs-----------
                    if (this.state.title.length < 1) {
                    alert("Enter a Title");
                    return;
                    }

                    if (this.state.description.length < 3) {
                    alert("Enter At least 3 words To describe the product ")
                    return;
                    }
                    if (this.state.storename.length < 1) {
                    alert("Enter a Storename")
                    return;
                    }
                    alert("Uploading Flyer" + this.state.title)
                    //------------------------------------------------
                    this.state.imagePath.forEach((data) => {

                    // coverting to base64
                    new Promise((resolve, reject) => {
                    fs.readFile(data, 'base64')
                    .then((data) => {

                        return Blob.build(data, { type: `${mime};BASE64` })

                    })
                    .then((blob) => { 
                        console.log("blob " +JSON.stringify(blob))
                        //uplaoding Image
                        uploadBlob = blob
                        name =name + 1
                        firebase.storage().ref(uid).child(name + ".jpg").put(blob) // ,{ contentType: mime }

                    })
                    .then(() => {
                        //uploadBlob.close()
                        //getting url
                        console.log("1")
                        return firebase.storage().ref(uid).child(name + ".jpg").getDownloadURL()

                    }) 
                    })
                    })
                    .then(() => {
                        //urls = url;
                        console.log('urls=' + urls)
                        //================================
                        try {


                        alert("Uploading Flyerss" + this.state.title)

                        //-------------------------------------------

                        //----------Inserting Data to Database--------


                        usersTable = 'flyers/' + this.state.productUid,
                            console.log(usersTable)
                        firebase.database().ref(usersTable).set(
                            {

                            title: this.state.title,
                            description: this.state.description,
                            imageUrls: this.state.imageUrls,
                            storename: this.state.storename,
                            user: asyncValue,
                            longitude: this.state.longitude,
                            latitutde: this.state.latitutde
                            }
                        ).then(
                            console.log("then"),
                            this.title.clear(),
                            this.description.clear(),
                            //this.category.clear(),
                            this.setState({ loading: false }),
                            this.setState({ disabled: false }),
                            this.setState({ title: "" }),
                            this.setState({ storename: "" }),
                            this.setState({ description: "" }),
                            this.setState({ imagePath: "" }),
                            urls = "",
                            alert(this.state.title + " flyer sucessfully uploaded")
                        )
                        //--------------------------------------------

                        }
                        catch (error) {
                        this.setState({ loading: false })
                        this.setState({ disabled: false })
                        console.log(error.toString())
                        alert(error.toString())
                        }
                        //================================



                    })
                }, 3000)
                }

                catch (error) {
                console.log("upload Error = " + error)
                }

            }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...