DINHDANH Creator · Bài EM05 · Easy · 7 method file trang / upload

File trang trên site & upload
đủ method - tham số · trả về · lưu ý

Khác kho JSON (EM03). Easy: upload không cần login admin (chỉ chìa khóa phiên trang) - cẩn thận form công khai.

So sánh nhanh: Kho dữ liệu lần đầu → success + rỗng · File trang chưa có → thường success: false.
appifio_readFsFile(filePath)

Việc: Đọc file trang (HTML/CSS/JS/JSON…) hoặc nhị phân (base64).

const r = await appifio_client.appifio_readFsFile('routes.json');
if (r.success) {
  const routes = JSON.parse(r.data.content); // text JSON → tự parse
}
// HTML: dùng r.data.content trực tiếp (chuỗi)

Trả về: { data: { content, … } }. Binary có thể kèm encoding. Chưa có path → success: false.

appifio_writeFsFile(filePath, content)

Tham số: đường dẫn tương đối trong site + chuỗi nội dung (html, css, js, json…).

await appifio_client.appifio_writeFsFile('blog/detail.html', htmlString);
await appifio_client.appifio_writeFsFile('backend/functions/greetUser.js', code);

Trả về: { success: true, data?: { path, size } }. Không dùng để ghi đuôi thực thi nguy hiểm (hệ thống từ chối).

appifio_deleteFsFile(filePath)
await appifio_client.appifio_deleteFsFile('blog/old.html');

Lưu ý: Không “xóa sạch” routes.json bằng tay để gỡ 1 URL - dùng removeRoute (EM06).

appifio_listFsFiles(subfolder?, pattern?)

Tham số Easy: subfolder (mặc định ''), pattern (mặc định '').

const r = await appifio_client.appifio_listFsFiles('blog', '*.html');

Khác Aura: Aura thường nhận object options { path, recursive } - Easy dùng hai chuỗi.

appifio_getFsFileInfo(filePath)
const r = await appifio_client.appifio_getFsFileInfo('routes.json');
// data: path, name, size, …
appifio_uploadImage(file)

Tham số: đối tượng File từ input - jpg/png/gif/webp/svg… · tối đa ~10MB.

const r = await appifio_client.appifio_uploadImage(input.files[0]);
const url = r.data.url; // gắn  hoặc lưu vào sổ JSON

Trả về: { data: { url: "…" } }. Aura: thường cần đã đăng nhập quản trị.

appifio_uploadFile(file)

Tham số: tài liệu (pdf, zip…) · tối đa ~50MB (theo giới hạn hệ thống).

const r = await appifio_client.appifio_uploadFile(input.files[0]);
// r.data.url
Checklist EM05 (7/7): readFsFile · writeFsFile · deleteFsFile · listFsFiles · getFsFileInfo · uploadImage · uploadFile

EM06 - Route (đủ method)

DINHDANH Creator · Loạt Easy Storage · EM05