REMINDER
SOLVED fileSaveUploaded issue (appdrag-cloudbackend node package)
-
@undefined that's correct
-
@jbenguira Thx for your assistance, I now understand how the event FILES works.
I'm actually facing a new problem and I still didn't find a solution...
I'm trying to extract the cdnPath result from the promise that is generated throught the use of the fileSaveUploaded function.I tried multiple methods :
var Myentry = await appdrag.fileSaveUploaded(event["FILES"][0]["path"], "XX-" + MyFormEntry + "_" + AnotherFormEntry + extension).then( async function(response) { answer = await response; console.log(answer); } );
(This is the last one i tried)
The problem is that console.log returns a promise, that when pushed to the database as a "link" is replaces by [promise object], using a return only takes the first { in account and don't paste the rest, using response.cdnPath returns an undefined value.
So, I'm trying to extract the cdnPath link that the function generates to post it proprely to the database, could somebody give me an advice of how to proprely grab it to POST it as a direct link ?
Thanks in advance.
-
(the actual console.log content)
{"status":"OK","execTime":1173,"billedTime":1200,"payload":"null","logs":"2021-07-27T09:12:59.362Z\t1d9a7104-bd32-4cd4-b39b-0c9948e8085c\tINFO\t{\"status\":\"OK\",\"directPath\":\"//someawsserver.com/dev.appdrag.com/test-****-*-******/CloudBackend/uploads/TheFirstFile.extension\",\"cdnPath\":\"//cf.appdrag.com/test-*****-*-******/CloudBackend/uploads/TheFirstFile.extension\\"}\n2021-07-27T09:12:59.577Z\t1d9a7104-bd32-4cd4-b39b-0c9948e8085c\tINFO\t{\"status\":\"OK\",\"directPath\":\"//someawsserver.com/dev.appdrag.com/test****-*-******/CloudBackend/uploads/TheSecondFile.extension\",\"cdnPath\":\"//cf.appdrag.com/test-****-*-******/CloudBackend/uploads/TheSecondFile.extension\"}\n2021-07-27T09:12:59.641Z\t1d9a7104-bd32-4cd4-b39b-0c9948e8085c\tINFO\t{ \"status\" : \"OK\", \"execTime\" : \"9\", \"billedTime\" : \"9\", \"affectedRows\" : \"1\"}\n"}
-
Up ?
-
@undefined in your code you have :
answer = await response;
this is incorrect, you can directly do:
console.log(response);
also no need to have async before the inline response
var Myentry = await appdrag.fileSaveUploaded(event["FILES"][0]["path"], "XX-" + MyFormEntry + "_" + AnotherFormEntry + extension).then( function(response) { console.log(response); } );
in fact you don't need to mess at all with async/await, just this should do it
appdrag.fileSaveUploaded(event["FILES"][0]["path"], "XX-" + MyFormEntry + "_" + AnotherFormEntry + extension).then( function(response) { console.log(response); } );
-
@joseph-benguira Hi ! Thanks for taking time to answer me
Well, the point is that I tried with the method you describe at first, then found out that it was sending a whole promise to the database, which can't be correctly used as an URL (direct link to the uploaded file), so I was trying to find a way to extract the cdnPath from that promise so I could get the link only, not the whole thing (The console print in my previous message shows what the console.log(response) returns to the browser).
The whole await & async things where just desperate attempts from me to post something else to the database than a whole promise object ...Well wait, i'll try again with your exact syntax replacing with my things and get back to here ...
-
Same problem, it stores the whole object instead of the specific url, didn't find a way to deal with it after few attempts, if somebody has another solution I would love to hear from it
-
@undefined I have quickly checked one project where I did this and here is the code:
if (event.FILES.length > 0) { file = JSON.parse(await appdrag.fileSaveUploaded( event["FILES"][0]["path"], `myfolder/${event["FILES"][0]["path"].split('/')[1]}`))['cdnPath']; }
so here the thing is you indeed need to await before calling appdrag.fileSaveUploaded, and also you need to parse the response as JSON, then you can access the field cdnPath
-
@joseph-benguira Works like a charm ! Thanks !
(should I close the topic or something ?)
-
@undefined Done, marked as solved