upload
Tải tệp lên lưu trữ đám mây oneentry.
Description
Phương thức này tải một tệp lên lưu trữ tệp đám mây. Truyền vào giá trị thu được từ loại đầu vào "file". Nó trả về một Promise mà khi hoàn thành sẽ trả về một đối tượng IUploadingReturn[].
Dữ liệu là đối tượng tệp (hoặc mảng), tìm hiểu thêm - Đối tượng File
FileUploading.upload(
file*,
fileQuery,
fileQuery.type*,
fileQuery.entity*,
fileQuery.id*,
fileQuery.width,
fileQuery.height,
fileQuery.compress
);
Parameters schema
Schema
file(bắt buộc): File | Blob
Tệp để tải lên
ví dụ: new File(["content"], "file.png", {"type": "image/png"})
fileQuery: IUploadingQuery
Tùy chọn để thiết lập các tham số truy vấn
ví dụ:
{
"type": "page",
"entity": "editor",
"id": 3787,
"width": 0,
"height": 0,
"compress": true,
"template": 1
}
fileQuery.type(bắt buộc): string
Loại, xác định tên thư mục trong lưu trữ.
ví dụ: "page"
fileQuery.entity(bắt buộc): string
Tên thực thể từ đó tệp được tải lên, xác định tên thư mục trong lưu trữ.
ví dụ: "editor"
fileQuery.id(bắt buộc): number
Định danh của đối tượng từ đó tệp được tải lên, xác định tên thư mục trong lưu trữ.
ví dụ: 3787
fileQuery.width: number
Tham số chiều rộng.
ví dụ: 0
fileQuery.height: number
Tham số chiều cao.
ví dụ: 0
fileQuery.compress: boolean
Cờ tối ưu hóa (nén) cho hình ảnh.
ví dụ: true
Examples
Minimal example
const fileQuery = { "type": "page", "entity": "editor", "id": 3787, "width": 0, "height": 0, "compress": true};
const response = await FileUploading.upload(file, fileQuery);
Example response
[
{
"filename": "files/project/page/3492/editor/856f57e4-8fa8-4862-bafe-3b36959a806e.md",
"downloadLink": "https://your-project.oneentry.cloud/cloud-static/files/project/page/3492/editor/856f57e4-8fa8-4862-bafe-3b36959a806e.md",
"size": 4463,
"contentType": "text/markdown"
}
]
Response schema
Schema: IUploadingReturn[]
filename: string
Tên tệp với đường dẫn tương đối.
ví dụ: "uploads/file.png"
downloadLink: string
Liên kết để tải xuống tệp.
ví dụ: "https://example.com/uploads/file.png"
size: number
Kích thước của tệp tính bằng byte.
ví dụ: 1024