_anomDiebolt_
9 years agoQrew Elite
How To Copy File Attachments Between Tables Without Download?
How To Copy File Attachments Between Tables Without Download?
This script is intended to be used from the console in its current form although it would not take much in the way of changes to use it within a QuickBase page on button click or other event. It is presented in this fashion to allow users to test it on various file types and in different browsers. I have tested it in Chrome on images, Word documents, pdf documents, MP3 files and it works flawlessly.
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=574
To use the script fill in these six parameters which represent the {dbid, [Record ID#] and field ID} for the source and target of the file you want to copy and paste the entirety of the script into the console (press F12 to expose):
The script does not use the QuickBase API so no application token is needed.
The function copyFile() returns a native JavaScript Promise (not a jQuery Promise) which resolves after the final POSTing of the file to the target locaiton. Since some file uploads can take a while you simply have to wait for the process to complete after pasting your script in the console.
Notes
(1) If some of the coding conventions look new to you the script extensively uses new ES6 features including (a) fat arrow (=> ) functions definitions, (b) let variable definitions, (c) backticks for string interpolation.
(2) The script uses native Promises not jQuery promises (no jQuery is used in this demo)
(3) The script uses the Fetch API which is the replacement for XHR. The whole reason this script can transfer binary files is because the Fetch API support sending blobs of binary data.
(4) The script used the FormData API to submit the file to the target location. The FormData API was the topic of one of my proposed Empower 2017 presentations but I was denied so I will give an impromptu presentation in the hallways if requested. I think I am going to get one of those mini hand held projectors:
https://www.webups.com/sites/default/files/aiptek-t20-pocket-cinema-mini-projector-3.jpg
and maybe one of those big popcorn maker carts:
http://www.fridgefanatic.com/nostalgia-electric/popcorn-machines/kpm508-kettle-popper-popcorn-maker-...
(5) A lot of work went into making the script as compact as possible and avoid a lot of ceremony. To make the most compact usage of QuickBase URL methods some parameters were used that you may not be readily familiar with. Ask if you are curious.
(6) This general trend of using advanced scripting technologies with QuickBase is just going to increase over time:
This script is intended to be used from the console in its current form although it would not take much in the way of changes to use it within a QuickBase page on button click or other event. It is presented in this fashion to allow users to test it on various file types and in different browsers. I have tested it in Chrome on images, Word documents, pdf documents, MP3 files and it works flawlessly.
Pastie Database
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=574
To use the script fill in these six parameters which represent the {dbid, [Record ID#] and field ID} for the source and target of the file you want to copy and paste the entirety of the script into the console (press F12 to expose):
let dbidSource = "YOUR SURCE DBID";Please let me know of your success and the conditions you used the script under. I would suggest you test the script in an isolated application to not interfere with your production applications and to simplify the test environment in the event there is an error.
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";
The script does not use the QuickBase API so no application token is needed.
The function copyFile() returns a native JavaScript Promise (not a jQuery Promise) which resolves after the final POSTing of the file to the target locaiton. Since some file uploads can take a while you simply have to wait for the process to complete after pasting your script in the console.
Notes
(1) If some of the coding conventions look new to you the script extensively uses new ES6 features including (a) fat arrow (=> ) functions definitions, (b) let variable definitions, (c) backticks for string interpolation.
(2) The script uses native Promises not jQuery promises (no jQuery is used in this demo)
(3) The script uses the Fetch API which is the replacement for XHR. The whole reason this script can transfer binary files is because the Fetch API support sending blobs of binary data.
(4) The script used the FormData API to submit the file to the target location. The FormData API was the topic of one of my proposed Empower 2017 presentations but I was denied so I will give an impromptu presentation in the hallways if requested. I think I am going to get one of those mini hand held projectors:
https://www.webups.com/sites/default/files/aiptek-t20-pocket-cinema-mini-projector-3.jpg
and maybe one of those big popcorn maker carts:
http://www.fridgefanatic.com/nostalgia-electric/popcorn-machines/kpm508-kettle-popper-popcorn-maker-...
(5) A lot of work went into making the script as compact as possible and avoid a lot of ceremony. To make the most compact usage of QuickBase URL methods some parameters were used that you may not be readily familiar with. Ask if you are curious.
(6) This general trend of using advanced scripting technologies with QuickBase is just going to increase over time:
- Greater abstractions through libraries and JavaScript language extensions
- More powerful client-side capabilities - the old restrictions on what can be done client-side are evaporating.
- More compact code and more usage of DSLs (Domain Specific Languages)