Forum Discussion

AdrinieFreeman's avatar
AdrinieFreeman
Qrew Trainee
5 years ago

File Attachment HELP

Hello all!
I need to know how I can get file attachments from one table to another. I'm currently using the automation tool to get everything else over.

------------------------------
Adrinie Freeman
------------------------------

11 Replies

  • This can't be done natively, but can be done with a Code Page or a formula button that will execute this. This is not my code, but Dan Diebolt's. He used to be very active on these boards.

    (() => {

      let dbidSource = "YOUR SOURCE DBID";

      let ridSource = "YOUR SOURCE [Record ID#]";

      let fidSource = "YOUR SOURCE FIELD ID";

     

      let dbidTarget = "YOUR TARGET DBID";

      let ridTarget = "YOUR TARGET [Record ID#]";

      let fidTarget = "YOUR TARGET FIELD ID";

     

      let copyFile = (dbidSource, ridSource, fidSource, dbidTarget, ridTarget, fidTarget) => {

        return new Promise(resolve => {

          let urlFileName = `${dbidSource}?a=q&query={3.EX.${ridSource}}&clist=${fidSource}&opts=csv`;

          fetch(urlFileName, {

            method: "GET",

            credentials: "include"

          }).then(response => {

            return response.text();

          }).then(response => {

            let filename = response.split("\n")[1].trim();

            let urlFileSource = `/up/${dbidSource}/a/r${ridSource}/e${fidSource}/v0`;

            fetch(urlFileSource, {

              method: "GET",

              credentials: "include"

            }).then(response => {

              return response.blob();

            }).then(myBlob => {

              let myform = new FormData();

              myform.set("subact", "save");

              myform.set("rid", ridTarget);

              myform.append(`_fid_${fidTarget}`, myBlob, filename);

              let urlFileTarget = `${dbidTarget}?a=FinishEditRecord`;

              fetch(urlFileTarget, {

                method: "POST",

                body: myform,

                credentials: "include"

              }).then(response => {

                resolve();

              });

            });

          });

        });

      };        

     

      copyFile(dbidSource, ridSource, fidSource, dbidTarget, ridTarget, fidTarget).then(() => {

        console.log("all done");

      });

     

    })();



    ------------------------------
    Ryan Stanford
    ------------------------------
  • We have an add-on service that can sweep the files for you if you don't want to code the process yourself.  Can also process in bulk based on a report filtered to identify the records to process.
     
    demo here: https://juicedtech.quickbase.com/db/bmzi5qjk7

    ------------------------------
    Keith Jusas
    ------------------------------
    • MarkShnier__You's avatar
      MarkShnier__You
      Qrew Champion

      The Juiced brothers are great and I highly recommend them. 


      But just to be sure you know all your options, if you only need to display an image or display a link to a file on another table then there is an easy formula for that. So in that use case the file remains stored in one place but is viewable on records in another table. The typical use cases when there is a relationship between the two tables.




      ------------------------------
      Mark Shnier (YQC)
      Quick Base Solution Provider
      Your Quick Base Coach
      http://QuickBaseCoach.com
      mark.shnier@gmail.com
      ------------------------------
      • MatthewStewart's avatar
        MatthewStewart
        Qrew Member
        Mark,
        Can you elaborate?

        ------------------------------
        Matthew Stewart
        ------------------------------