Skip to content

Commit 3e1732b

Browse files
committed
downloadHandler temp files should have same extension as final download file
1 parent 4eb18dc commit 3e1732b

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ shiny 0.11.0.9xxx
1111
* Switched from RJSONIO to jsonlite. This improves consistency and speed when
1212
converting between R data structures and JSON.
1313

14+
* downloadHandler content callback functions are now invoked with a temp file
15+
name that has the same extension as the final filename that will be used by
16+
the download. This is to deal with the fact that some file writing functions
17+
in R will auto-append the extension for their file type (pdf, zip).
18+
1419
shiny 0.11
1520
--------------------------------------------------------------------------------
1621

R/shiny.R

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,15 @@ ShinySession <- R6Class(
697697
'Cache-Control' = 'no-cache')))
698698
}
699699

700-
tmpdata <- tempfile()
700+
# Make temp file with the same extension as the user-visible filename.
701+
# If the extension is not used, some functions such as pdf() and zip()
702+
# may append the extension they expect, meaning the data we want will
703+
# be written to a file other than our temp file (e.g. file1231.zip
704+
# instead of file1231.zip).
705+
ext <- tools::file_ext(filename)
706+
if (nzchar(ext))
707+
ext <- paste(".", ext, sep = "")
708+
tmpdata <- tempfile(fileext = ext)
701709
result <- try(Context$new(getDefaultReactiveDomain(), '[download]')$run(
702710
function() { download$func(tmpdata) }
703711
))

man/parseQueryString.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ list(i1 = list(j1 = 'x')), b = list(i1 = list(j1 = 'y'), i2 = list(j1 =
1717
`b[i1][j1]` = 'y', `b[i2][j1]` = 'z')} when \code{nested = FALSE}.}
1818
}
1919
\description{
20-
Returns a named character vector of key-value pairs.
20+
Returns a named list of key-value pairs.
2121
}
2222
\examples{
2323
parseQueryString("?foo=1&bar=b\%20a\%20r")

0 commit comments

Comments
 (0)