| FileUploadsEndpoint | R Documentation |
Handle all file uploads operations in the Notion API
Note: Access this endpoint through the client instance, e.g., notion$file_uploads. Not to be instantiated directly.
A list containing the parsed API response.
new()Initialise file uploads endpoint.
Not to be called directly, e.g., use notion$file_uploads instead.
FileUploadsEndpoint$new(client)
clientNotion Client instance
create()Create a file upload
FileUploadsEndpoint$create( mode = NULL, filename = NULL, content_type = NULL, number_of_parts = NULL, external_url = NULL )
modeCharacter. How the file is being sent. Use "multi_part" for files larger than 20MB. Use "external_url" for files that are temporarily hosted publicly elsewhere. Default is "single_part".
filenameCharacter. Name of the file to be created. Required when mode
is "multi_part". Must include an extension, or have one inferred from
the content_type parameter.
content_typeCharacter. MIME type of the file to be created.
number_of_partsInteger. When mode is "multi_part", the number of parts
you are uploading.
external_urlCharacter. When mode is "external_url", provide the
HTTPS URL of a publicly accessible file to import into your workspace.
send()Upload a file
FileUploadsEndpoint$send(file_upload_id, file, part_number = NULL)
file_upload_idCharacter (required). Identifier for a Notion file upload object.
fileNamed list (JSON object). The raw binary file contents to upload. Must contain named elements:
filename. Character. The name of the file, including it's extension (e.g., "report.pdf")
data. Raw. The binary contents of the file, as returned by e.g., readBin()
type. Character. Optional. The MIME type of the file (e.g., "application/pdf", "image/png").
If not supplied, the type is inferred from filename by curl::form_file().
Supported file types are listed here.
part_numberCharacter. The current part number when uploading files greater than 20MB in parts. Must be an integer between 1 and 1,000
complete()Complete a multi-part file upload
FileUploadsEndpoint$complete(file_upload_id)
file_upload_idCharacter (required). Identifier for a Notion file upload object.
retrieve()Retrieve a file upload
FileUploadsEndpoint$retrieve(file_upload_id)
file_upload_idCharacter (required). Identifier for a Notion file upload object.
list()List file uploads
FileUploadsEndpoint$list(status = NULL, start_cursor = NULL, page_size = NULL)
statusCharacter. If supplied, the endpoint will return file uploads with the specified status. Available options are "pending", "uploaded", "expired", "failed".
start_cursorCharacter. For pagination. If provided, returns results starting from this cursor. If NULL, returns the first page of results.
page_sizeInteger. Number of items to return per page (1-100). Defaults to 100
notion <- notion_client()
# ----- Direct upload (files <= 20MB)
# Step 1: Create a File Upload object
(resp <- notion$file_uploads$create("single_part"))
file_upload_id <- resp[["id"]]
# Step 2: Upload file contents
#* replace with your file
path <- file.path(tempdir(), "test.pdf")
writeBin(charToRaw("placeholder"), path)
raw <- readBin(path, "raw", file.size(path))
notion$file_uploads$send(
file_upload_id,
list(
filename = basename(path),
data = raw
)
)
# Retrieve the file upload
notion$file_uploads$retrieve(file_upload_id)
# ----- Multi-part upload (files > 20MB)
# Step 1: Split raw content into parts
#* replace with your file
raw <- as.raw(rep(65L, 11 * 1024 * 1024))
mid <- ceiling(length(raw) / 2)
parts <- list(raw[seq_len(mid)], raw[seq(mid + 1L, length(raw))])
# Step 2: Create a File Upload object
(resp <- notion$file_uploads$create(
mode = "multi_part",
filename = "test-large.txt",
number_of_parts = 2L
))
file_upload_id <- resp[["id"]]
# Step 3: Send each part
for (i in seq_along(parts)) {
notion$file_uploads$send(
file_upload_id,
file = list(
filename = "test-large.txt",
data = parts[[i]]
),
part_number = as.character(i)
)
}
# Step 4: Complete the upload
notion$file_uploads$complete(
file_upload_id
)
# Retrieve the file upload
notion$file_uploads$retrieve(
file_upload_id
)
# ----- Import external files
notion$file_uploads$create(
"external_url",
"dummy.pdf",
content_type = "application/pdf",
external_url = "https://github.com/brenwin1/notionapi/blob/main/tests/testthat/test.pdf"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.