Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    SOLVED fileSaveUploaded issue (appdrag-cloudbackend node package)

    Cloud Backend (Cloud DB, API Builder)
    3
    13
    1160
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jbenguira @Hamza HAMZAOUI last edited by

      @undefined that's correct 🙂

      H 1 Reply Last reply Reply Quote 1
      • H
        Hamza HAMZAOUI @jbenguira last edited by

        @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.

        H 2 Replies Last reply Reply Quote 0
        • H
          Hamza HAMZAOUI @Hamza HAMZAOUI last edited by

          (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"}
          
          1 Reply Last reply Reply Quote 0
          • H
            Hamza HAMZAOUI @Hamza HAMZAOUI last edited by

            Up 😕 ?

            Joseph Benguira 1 Reply Last reply Reply Quote 0
            • Joseph Benguira
              Joseph Benguira @Hamza HAMZAOUI last edited by Joseph Benguira

              @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);
                      }
                  );
              
              H 1 Reply Last reply Reply Quote 0
              • H
                Hamza HAMZAOUI @Joseph Benguira last edited by

                @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 ...

                H 1 Reply Last reply Reply Quote 0
                • H
                  Hamza HAMZAOUI @Hamza HAMZAOUI last edited by

                  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 🙂

                  Joseph Benguira 1 Reply Last reply Reply Quote 0
                  • Joseph Benguira
                    Joseph Benguira @Hamza HAMZAOUI last edited by

                    @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 😉

                    H 1 Reply Last reply Reply Quote 1
                    • H
                      Hamza HAMZAOUI @Joseph Benguira last edited by

                      @joseph-benguira Works like a charm ! Thanks !

                      (should I close the topic or something 😮 ?)

                      Joseph Benguira 1 Reply Last reply Reply Quote 0
                      • Joseph Benguira
                        Joseph Benguira @Hamza HAMZAOUI last edited by

                        @undefined Done, marked as solved 😉

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post