downloadFile
Lưu ý
Cần xin cấp quyền tại trang Quản lý ứng dụng
import { downloadFile } from "zmp-sdk/apis"; // >= 2.44.0
API hỗ trợ tải file về thiết bị. 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 | Đuôi file |
---|---|
Văn bản | pdf, doc, docx, odt, xls, xlsx, ppt, pptx, txt, rtf, csv |
Hình ảnh | jpg, jpeg, png, gif, bmp |
Video | mp4, 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!");
Xử lý lỗi khi tải file (tham khảo bảng mã lỗi tại đây):
try {
await downloadFile({
url: "https://stc-zmp.zadn.vn/mini-app/landingpage-banner-new.png",
});
} catch (error) {
// Đã có lỗi xảy ra
console.error(error);
}
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!");
Tham số
Truyền tham số vào API dưới dạng object chứa các thuộc tính:
Name | Type | Default | Description |
---|---|---|---|
url | string |
| |
onProgress | (progress: number) => void |
|
Errors
Code | Message | Note |
---|---|---|
-301 | Your device run out of storage | |
-302 | File cannot be found. Please check your param again. | Không tìm được file. Có 2 trường hợp dẫn đến lỗi
|
-303 | Please wait... We're still download the file. | |
-304 | No Internet connection. Please check your network settings. | |
-305 | Download failed. Please check your network or file path again. | |
-306 | File type unsupported | Tham khảo danh sách file hỗ trợ |