Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field Data) #334

Closed
andrecosta99 opened this issue Aug 21, 2020 · 1 comment

Comments

@andrecosta99
Copy link

Hi Everybody,

I'm learning JS and in a project, for the university, I can't resolve this error in my app. This happens when I'm uploading a document to google firebase fire storage:

Print App: https://ibb.co/K0ccBqL
Print Error:https://ibb.co/7CqwNhB
Text Error:

error.ts:168 Uncaught FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field Data)
at new t (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:47215)
at r.createError (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:314392)
at t.parseScalarValue (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:319819)
at t.parseData (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:317720)
at https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:317895
at Ur (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:47878)
at t.parseObject (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:317868)
at t.parseData (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:317469)
at t.parseSetData (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:315197)
at n.set (https://www.gstatic.com/firebasejs/6.2.0/firebase-firestore.js:1:335038)

My Javascipt function to insert documents:
function Inserir() {

    $("#sendDiv").show();

    var nome = $("#docname").val();
    var data = $("#verificationdate").val();

    var fp = $("#file");
    //var lg = fp[0].files.length; // get length
    var items = fp[0].files;
    var fileType = items[0].type; // get file type
    var file = items[0];

    // Add a new document in collection Iduser
    db.collection(iduser).doc(nome).set({
        Nome: nome,
        Data: data,
        Imagem: nome
    })
        .then(function () {
            //alert("Documento Inserido!");               
        })
        .catch(function (error) {
            navigator.notification.alert("Please, try again!", "", "Error", "Ok");
        });


    //envio ficheiro
    var metadata = {
        'contentType': fileType
    };

    var auth = firebase.auth();
    var storageRef = firebase.storage().ref();

    storageRef.child(iduser + '/' + nome).put(file, metadata)

        .then(function (snapshot) {

            $("#sendDiv").hide();
            navigator.notification.alert("Successfully uploaded!", "", "We Simplify", "Ok");

            $("#docname").val("");
            $("#verificationdate").val("");
            $("#file").val("");

            $.mobile.changePage("#page_newmenu");

            // Let's get a download URL for the file.
            //snapshot.ref.getDownloadURL().then(function (url) {
            //    //console.log('File available at', url);                   
            //});
        })

        .catch(function (error) {
            //console.error('Upload failed:', error);               
        });
}//Inserir

I don't know if it helps but I can see all the documents I insert manually in the fire storage admin panel, as I can create users and login... even in the past when I've made my first app in the visual studio 2017 it worked fine with this code. Now I'm working with Cordova in visual studio code everything perfect less this error.

Your help would be very valuable to me.
Thanks in advance.

@kevmoo
Copy link
Contributor

kevmoo commented Oct 14, 2020

Sorry. Looks like you're using javascript. This project is in Dart.

@kevmoo kevmoo closed this as completed Oct 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants