Skip to main content

upload

Upload a file to OneEntry cloud storage.

Description​

Uploads a single File or Blob (for example, from an <input type="file">) to cloud storage and resolves to an array of IUploadingReturn.

fileQuery.type, fileQuery.entity and fileQuery.id set the storage folder. All three are required: the API rejects the upload with 400 if any of them is missing.

.upload(

,

);

Parameters schema​

Schema

file(required): File | Blob
File to upload.
example:

new File(["content"], "file.png", {"type": "image/png"})

fileQuery(required): IUploadingQuery
Where the file is stored. Required: without type, entity and id the endpoint answers 400 … should not be empty.
example:

{
"type": "page",
"entity": "editor",
"id": 3787,
"width": 0,
"height": 0,
"compress": true,
"template": 1
}

fileQuery.type(required): string
Storage type; determines the folder the file is stored in, for example "page".
example: "page"

fileQuery.entity(required): string
Name of the entity the file belongs to; sets the folder name in the storage.
example: "editor"

fileQuery.id(required): number
ID of the object the file belongs to; sets the folder name in the storage.
example: 3787

fileQuery.width: number
Not used by the upload and delete endpoints.
example: 0

fileQuery.height: number
Not used by the upload and delete endpoints.
example: 0

fileQuery.compress: boolean
Whether to compress (optimize) uploaded images.
example: true

Examples​

Minimal example​


const = {
,
,
,
};

const response = await FileUploading.upload(file, fileQuery);

Example response​

[
{
"filename": "files/project/page/3492/editor/cdf6fb02-0a93-4f0e-9877-5f8ffeb00414.md",
"downloadLink": "https://your-project.oneentry.cloud/cloud-static/files/project/page/3492/editor/cdf6fb02-0a93-4f0e-9877-5f8ffeb00414.md",
"size": 4463,
"contentType": "text/markdown"
}
]

Response schema​

Schema: IUploadingReturn[]

filename: string
File name with its 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

contentType: string
MIME type of the uploaded file.
example: "image/png"