FileSystemEntry: getMetadata() method
Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
Phương thức getMetadata() của giao diện FileSystemEntry lấy một đối tượng Metadata với thông tin về mục hệ thống tệp, chẳng hạn như ngày và giờ sửa đổi cũng như kích thước của nó.
Cú pháp
getMetadata(successCallback)
getMetadata(successCallback, errorCallback)
Tham số
successCallback-
Hàm được gọi khi thao tác hoàn tất thành công. Nhận một tham số đầu vào duy nhất: một đối tượng
Metadatavới thông tin về tệp. errorCallbackOptional-
Callback tùy chọn được thực thi nếu xảy ra lỗi khi tra cứu siêu dữ liệu. Có một tham số duy nhất: một
DOMExceptionmô tả lỗi xảy ra.
Giá trị trả về
Không có (undefined).
Ngoại lệ
DOMException.NOT_FOUND_ERR-
FileSystemEntrytham chiếu đến một mục không tồn tại. DOMException.SECURITY_ERR-
Các hạn chế bảo mật ngăn cản việc lấy siêu dữ liệu được yêu cầu.
Ví dụ
Ví dụ này kiểm tra kích thước của tệp nhật ký trong thư mục tạm thời và nếu vượt quá một megabyte, sẽ chuyển nó sang thư mục khác.
workingDirectory.getFile(
"tmp/log.txt",
{},
(fileEntry) => {
fileEntry.getMetadata((metadata) => {
if (metadata.size > 1048576) {
workingDirectory.getDirectory(
"log",
{},
(dirEntry) => {
fileEntry.moveTo(dirEntry);
},
handleError,
);
}
});
},
handleError,
);