Uploading a large dataset to Zenodo with R

It is sometimes useful to upload a large dataset to Zenodo. For example, if you are wanting to register a derived dataset.

I have found that large datasets tend not to be handled well by the Zenodo UI. In these cases, uploading via the Zenodo API tends to work better.

I wrote a script below in R that will upload a dataset to a started/unpublished Zenodo deposit.

This script requires a personal access token, which you can get here.

# zenodo large file upload

library(httr) 
library(dplyr)
library(purrr)

# get your token here
# https://zenodo.org/account/settings/applications/
token <- "long_ugly_number_you_get_from_zenodo"
deposit_id <- 6137047 # fill in UI form to get this number
file <- "file_you_want_to_upload.zip"

bucket <- GET(paste0("https://www.zenodo.org/api/deposit/depositions/",deposit_id), 
add_headers(Authorization = paste("Bearer", token)),
encode = 'json'
) %>% 
content(as = "text") %>% 
jsonlite::fromJSON() %>% 
pluck("links") %>% 
pluck("bucket") %>% 
gsub("https://zenodo.org/api/files/","",.)

PUT(url = paste0("https://www.zenodo.org/api/files/",bucket,"/",file,"?access_token=",token), 
body = upload_file(file) # path to your local file
) %>% 
content(as = "text")

This script was inspired by

@jhpoelen

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.