shiny icon indicating copy to clipboard operation
shiny copied to clipboard

Download's content type is not guessed based on extension and returns NA

Open bersbersbers opened this issue 3 years ago • 0 comments

System details

Browser Version: Chrome 98, Firefox 97

Output of sessionInfo():

R version 4.1.2 (2021-11-01)
Platform: x86_64-suse-linux-gnu (64-bit)
Running under: openSUSE Leap 15.2

Matrix products: default
BLAS:   /usr/lib64/R/lib/libRblas.so
LAPACK: /usr/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shiny_1.7.1

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.8       digest_0.6.29    later_1.3.0      mime_0.12       
 [5] R6_2.5.1         jsonlite_1.8.0   lifecycle_1.0.1  xtable_1.8-4    
 [9] magrittr_2.0.2   cachem_1.0.6     rlang_1.0.1      cli_3.2.0       
[13] promises_1.2.0.1 jquerylib_0.1.4  bslib_0.3.1      ellipsis_0.3.2  
[17] tools_4.1.2      import_1.2.0     glue_1.6.1       httpuv_1.6.5    
[21] fastmap_1.1.0    compiler_4.1.2   htmltools_0.5.2  sass_0.4.0      

Example application or steps to reproduce the problem

ui <- shiny::fluidPage(shiny::downloadLink("downloadData", "Download"))

server <- function(input, output) {
    output$downloadData <- shiny::downloadHandler(
        filename = "bug.zip",
        content = \(file) write.csv(1, file),
    )
}

shiny::shinyApp(ui, server)

Describe the problem in detail

https://shiny.rstudio.com/reference/shiny/1.7.0/downloadHandler.html says:

contentType A string of the download's content type, for example "text/csv" or "image/png". If NULL or NA, the content type will be guessed based on the filename extension, or application/octet-stream if the extension is unknown.

(By the way, "text/csv" and application/octet-stream are quoted inconsistently.)

However, the download above reports a Content-Type NA in both Firefox and Chrome:

image

image

image

image

bersbersbers avatar Feb 24 '22 09:02 bersbersbers