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

Bắt đầu hỗ trợ ở phiên bản:

  • SDK: 2.51.0
  • Android: 25.11.02
  • IOS: 25.12.02

Lưu file từ network hoặc file tạm về vùng nhớ cục bộ (local data). Hỗ trợ tải file với các định dạng được liệt kê tại đây.

Parameters

Object object

PropertyTypeDefaultRequiredDescriptionMinimum Version
filePathstringtrueĐường dẫn tới file trên network hoặc file tạm (trả về sau khi gọi API openMediaPicker) của mini app
successfunctionCallback function khi gọi api thành công
failfunctionCallback function khi gọi api thất bại

Return Values

Promise <Object data>

PropertyTypeDescriptionMinimum Version
savedPathstringĐường dẫn tới file đã được lưu cục bộ

Sample Code

import { LFSStorage } from 'zmp-sdk/apis';

LFSStorage.saveFile({
filePath: "[Đường dẫn tới file]",
success: (data) => {
// xử lý khi gọi api thành công
const { savedPath } = data;
},
fail: (error) => {
// xử lý khi gọi api thất bại
console.log(error);
},
});

// hoặc

import { LFSStorage } from 'zmp-sdk/apis';

const saveFile = async () => {
try {
const { savedPath } = await LFSStorage.saveFile({
filePath: "[Đường dẫn tới file]",
});
} catch (error) {
// xử lý khi gọi api thất bại
console.log(error);
}
};

Errors

CodeMessageNote
-300Your max 10MB of local storage data is reachedDung lượng của folder lưu trữ local cache files giới hạn là 10MB. Xóa file cũ không cần thiết để có thể lưu thêm file. Tham khảo Xoá local file đã lưu
-301Your device run out of storage
-302File 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
  • Path sử dụng http (Chỉ hỗ trợ https)
  • File không tồn tại
-303Please wait... We're still download the file.
-304No Internet connection. Please check your network settings.
-305Download failed. Please check your network or file path again.
miniapp-logo

Khám phá