Reputation: 343
I have created a form on Shiny which has fileInput button to upload only .pdf extension file.But while testing it i found that it's accepting all kind of file type however i have mentioned .pdf in accept parameter of fileInput shown in below codes:
fileInput("fileid","Upload .pdf file only",multiple = FALSE, accept = c('.pdf'),width = "250px")
screenshot below that accepts all kind of file type:
accepting .xls file type
Accepting .csv file type:
I am looking for a solution that restrict user to upload .pdf file only and won't allow user to upload if some other file is selected.
Any help would be appreciated. :)
Upvotes: 2
Views: 1397
Reputation: 5254
You can and must verify that yourself in your server function. fileInput
gives you the MIME type and you can validate that has the correct type before you load it.
output$DisplayFileContent <- renderPrint({
req(input$fileid)
# Check for file type
if (input$fileid$type != "application/pdf") stop("No PDF")
pdffile <- readBin(con=input$file_input$datapath, what = 'raw',n=input$file_input$size)
# ... more code to show file content
})
Upvotes: 5