Write a submission's screenshots and recordings to files
Source:R/submission.R
extract_submission_media.RdA pasted screenshot (question()'s allow_image) or a voice recording
(allow_audio) sits in the downloaded file as a base64 data URL, which
nothing opens directly. This writes each one to dir as
<question id>.<ext> (.webp or .jpg for a screenshot, .webm for
a recording), so a grader can look or listen. load_tutorial() is the
alternative: it shows them in place, in the tutorial.
Arguments
- path
Path to a JSON file downloaded via
download_answers_button().- dir
Directory to write into, created if needed. Defaults to a directory named after the file, beside it.
- quiet
If
FALSE, the default, say what was written.
Value
Invisibly, a character vector of the files written, named by question id. Empty when the file holds no media.
Examples
answers <- tempfile(fileext = ".json")
writeLines(paste0(
'{"answers": [{"id": "plot-1", "answer": "data:image/webp;base64,',
jsonlite::base64_enc(charToRaw("not really an image")), '"}]}'
), answers)
files <- extract_submission_media(answers, dir = tempfile())
#> Wrote 1 file(s) to '/tmp/RtmpconCn7/file1a32613cc097': plot-1.webp
basename(files)
#> [1] "plot-1.webp"