Chuyển tới nội dung chính

downloadFile

import { downloadFile } from "zmp-sdk";

API hỗ trợ tải file về thiết bị, kích thước file được quy định như sau:

Hệ máyKích thước tối đa
Androidkhông quy định
iOS100Mb

Hỗ trợ giao thức tải file https:// với các định dạng được liệt kê bên dưới:

Định dạng file được hỗ trợ

Định dạngĐuôi file
Văn bảnpdf, doc, docx, odt, xls, xlsx, ppt, pptx, txt, rtf, csv
Hình ảnhjpg, jpeg, png, gif, bmp
Videomp4, avi, mkv, mov, wmv

Ví dụ

Thông báo một lần sau khi tải file xong:

await downloadFile({
url: "https://stc-zmp.zadn.vn/mini-app/landingpage-banner-new.png",
});
console.log("Tải file thành công!");

Báo cáo tiến độ tải file:

await downloadFile({
url: "https://stc-zmp.zadn.vn/mini-app/landingpage-banner-new.png",
onProgress: (progress) => {
console.log(`Đã tải được ${progress}%...`);
},
});
console.log("Tải file thành công!");

Xem hướng dẫn xử lý lỗi và bảng mô tả chi tiết mã lỗi tại đây.

Tham số

Truyền tham số vào API dưới dạng object chứa các thuộc tính:

PropertyTypeRequiredDescription
urlstringNoĐường dẫn của file muốn download.
fileBase64DatastringNoDữ liệu base64 của file muốn lưu (tối đa 7.000.000 ký tự).
onProgress(progress: number) => voidNoCallback function tiến độ tải file. Với progress là số từ 0 đến 100%.

Nếu truyền đồng thời urlfileBase64Data, SDK sẽ ưu tiên fileBase64Data.