3

I am using node js to upload content in quickblox. Following is the code I am using.

While uploading a picture i get an error of

var inputFile = $("input[type=file]")[0].files[0]; ^ $ is not defined

exports.upload = function(req, res){
    var CREDENTIALS ={
    appId: 0000,
    authKey: 'xxxxx',
    authSecret: 'yyyyyyyy'
    };
QB.init(CREDENTIALS.appId, CREDENTIALS.authKey, CREDENTIALS.authSecret);
     var user ={
    id: 1234,
    name: 'abcd',
    email: 'ab@gmail.com',
    pass: 'qwertyuiop'
    };

QB.createSession({email: user.email, password: user.pass
    }, function(err,res){
    console.log(res)
    if (res){
        var inputFile = $("input[type=file]")[
                0
            ].files[
                0
            ];
        var params ={name: inputFile.name, file: inputFile, type: inputFile.type, size: inputFile.size, 'public': false
            };
        QB.content.createAndUpload(params, function(err, response){
        if (err){
           console.log(err);
                } 
        else{
           console.log(response);   
           var uploadedFile = response;
           var uploadedFileId = response.id;
                }
            });
        }
    });
}
Bernard Vander Beken
  • 4,848
  • 5
  • 54
  • 76
Shivani Tyagi
  • 71
  • 1
  • 5

1 Answers1

1

Use document.querySelector("input[type=file]").files[0] instead $("input[type=file]")[0].files[0]. Or add JQuery