How to copy file from one table to another? #4
-
|
On project, Baso Aci Akang, 454, I have three separate tables, To resolve performance issue, we decide to just include these lookup items to insert row for Then on GCF, I simply select menu by its id and insert it on order_item, But, once I check on editor, this error shows up, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
|
@miftahulmuhaemen mas bisa confirm function yg dibuat di GCF itu pake admin secret role apa ? dan pas editor display error ini {"statusCode":500,"code":"NoSuchKey","error":"Internal Server Error","message":"The specified key does not exist."} ini rolenya apa? |
Beta Was this translation helpful? Give feedback.
-
|
mas @miftahulmuhaemen mintol coba yg di GCF admin secretnya disesuain sm role yg di editor qore apps mas. |
Beta Was this translation helpful? Give feedback.
-
|
Ini aku udah buat solusi sementara, selama Qore mungkin akan develop fungsi copy file dari satu tabel ke tabel lain. //Code written in Typescript.
import fetch, {Headers} from 'cross-fetch';
import * as Constant from '../utils/const';
import * as FormData from 'form-data';
export const storageToken = async (env: string) => {
const res = await fetch(
`${
env === Constant.PRODUCTION
? process.env.QOREBASE_PROD_URL
: process.env.QOREBASE_URL
}/v1/storage/token`,
{
method: 'POST',
headers: new Headers([
['x-qore-engine-admin-secret', `${process.env.QOREBASE_ADMIN_SECRET}`],
]),
}
);
const response = await res.json();
if (response.statusCode >= 400) {
throw response.message;
}
return response.token;
};
export const fileTokenTable = async (
table: string,
column: string,
row: string,
access: string,
env: string
) => {
const res = await fetch(
`${
env === Constant.PRODUCTION
? process.env.QOREBASE_PROD_URL
: process.env.QOREBASE_URL
}/v1/files/token/table/${table}/id/${row}/column/${column}?access=${access}`,
{
method: 'GET',
headers: new Headers([
['x-qore-engine-admin-secret', `${process.env.QOREBASE_ADMIN_SECRET}`],
]),
}
);
const response = await res.json();
if (response.statusCode >= 400) {
throw response.message;
}
return response.token;
};
export const copyFile = async (
filename: string,
imageURL: string,
token: string,
env: string
) => {
const arrayBuffer = await fetch(imageURL).then(res => {
return res.arrayBuffer();
});
const buffer = Buffer.from(arrayBuffer);
const formData = new FormData();
formData.append('file', buffer, {filename: filename});
return await new Promise(resolve => {
formData.submit(
{
host: `${
env === Constant.PRODUCTION
? process.env.QOREBASE_PROD_URL
: process.env.QOREBASE_URL
}`.replace('https://', ''),
path: `/v1/files/upload?token=${token}`,
headers: {
'x-qore-engine-admin-secret': `${process.env.QOREBASE_ADMIN_SECRET}`,
},
},
(err, res) => {
if (err) throw err;
if (Number(`${res.statusCode}`) >= 400)
throw new Error('Upload file failed');
resolve(res);
}
);
});
}; const readToken = await storageToken(env);
const writeToken = await fileTokenTable(
'order_items',
'menu_image',
`${rowID}`,
'write',
env
);
await copyFile(
`${menu.menu_image.filename}`,
`${menu.menu_image.url}?token=${readToken}`,
writeToken,
env
); |
Beta Was this translation helpful? Give feedback.



Ini aku udah buat solusi sementara, selama Qore mungkin akan develop fungsi copy file dari satu tabel ke tabel lain.
Boleh dikasih checkmark mba, mas hhe.
cc @Dewiif @hilmanfjrsy