Posting binary WAV file from javascript to R shiny server.
// See also http://stackoverflow.com/a/27228544/2596404 | |
// Blob is your binary data. | |
// blob = ...; | |
// Encode the data and post to server. | |
var reader = new FileReader(); | |
reader.readAsDataURL(blob); | |
reader.onloadend = function() { | |
base64data = reader.result; | |
// Trigger the change event on the form field to activate the reactive field on the server. | |
$('#audio').val(base64data).change(); | |
// Submit the form by triggering the click event on the button. | |
$('#btnUpload').click(); | |
} |
shinyServer(function(input, output, session) { | |
observeEvent(input$btnUpload, { | |
# Decode wav file. | |
audio <- input$audio | |
audio <- gsub('data:audio/wav;base64,', '', audio) | |
audio <- gsub(' ', '+', audio) | |
audio <- base64Decode(audio, mode = 'raw') | |
# Save to file on server. | |
inFile <- list() | |
inFile$datapath <- paste0('temp', sample(1:100000, 1), '.wav') | |
inFile$file <- file(inFile$datapath, 'wb') | |
writeBin(audio, inFile$file) | |
close(inFile$file) | |
# ... | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
Thank you very much. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Thank you so much for publishing this, this helped me out!