upload
Upload file to oneentry cloud storage.
Description
This method uploads a file to a cloud file storage. Pass to the date the value obtained from input type "file". It returns a Promise that resolves to an IUploadingReturn[] object.
Data is file object (or array), learn more - File Object
FileUploading.upload(
file*,
fileQuery,
fileQuery.type*,
fileQuery.entity*,
fileQuery.id*,
fileQuery.width,
fileQuery.height,
fileQuery.compress
);
Parameters schema
Schema
file(required): File | Blob
File to upload
example: new File(["content"], "file.png", {"type": "image/png"})
fileQuery: IUploadingQuery
Optional set query parameters
example:
{
"type": "page",
"entity": "editor",
"id": 3787,
"width": 0,
"height": 0,
"compress": true,
"template": 1
}
fileQuery.type(required): string
Type, determines the folder name in the storage.
example: "page"
fileQuery.entity(required): string
Entity name from which the file is uploaded, determines the folder name in the storage.
example: "editor"
fileQuery.id(required): number
Identifier of the object from which the file is uploaded, determines the folder name in the storage.
example: 3787
fileQuery.width: number
Width parameter.
example: 0
fileQuery.height: number
Height parameter.
example: 0
fileQuery.compress: boolean
Flag of optimization (compression) for images.
example: 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/7b949671-f7ed-4caa-b3c9-44b12cf0e7b4.md",
"downloadLink": "https://your-project.oneentry.cloud/cloud-static/files/project/page/3492/editor/7b949671-f7ed-4caa-b3c9-44b12cf0e7b4.md",
"size": 4463
}
]
Response schema
Schema: IUploadingReturn[]
filename: string
Filename with relative path.
example: "uploads/file.png"
downloadLink: string
Link for downloading the file.
example: "https://example.com/uploads/file.png"
size: number
Size of the file in bytes.
example: 1024