how to retrieve the url string of uploaded file outside the cloudinary.v2.uploader.upload() method scope
Hi i am having very similar issue. i am trying to save the url of the input files on my database after they are uploaded to cloudinary but i can't find anyway to retrieve the url string of the uploaded files.
The cloudinary.v2.uploader.upload(" ", { }, function(error, result) ) method returns a result after the files are uploaded and i am able to access the result.url which has the url string of the uploaded file but i can not access the string outside the method even when i store it in a different variable which is created outside the scope of the method.
i have tried to print it on the console.log screen and is shows an empty string and even when i try to upload the string to the database it updates with empty string on the field.
I have been trying to solve this problem for over two days now. Any help would go a very long way as i am stuck with my project and have checked to find a solution everywhere online. Thank you very much.
I use nodeJS on cloud 9 by the way.
-
Hi Felix,
I will recommend declaring the variable as a global variable and that way you can access it from any function.
Here is an example:
var ....;
var iurl; //global variable
app.post('/', function (req, res){
cloudinary.uploader.upload(path, function (result) {
for(var attributename in result){
if(attributename=='url'){
iurl=result[attributename] //assigning value to iurl variable
}
}
});
myLogger(iurl); //calling a function outside of app.post and passing iurl value
});
var myLogger = function (reqs) {
console.log(reqs); //printing the value
}0
Post is closed for comments.
Comments
1 comment