Download Handler Check if File Exists

I'm using the download handler with a GET using httr package, which sends an XLSX file. The code i have below works, but the question i have is there a way to check if that file any exists/return from the GET prior to sending a generated file out? Right now, if the file doesn't exist, the code still creates a blank file (which I'd like to avoid).

  download_link_file <- reactive({
    url <-  paste0(EXPORT_DOWNLOAD_URL, '-', values$SOME_ID)
    url
  })

  output$downloadDataLink <- downloadHandler(
    filename = function() {
      paste("file-export", "-", Sys.Date(), ".xlsx", sep="")
    },
    content = function(file) {
      GET(download_link_file(), write_disk(file))
    },
      contentType = "excel"
  )

Something like perhaps?

output$downloadDataLink <- downloadHandler(
  
  if (length(download_link_file()) == 1){
    
    filename = function() {
      paste("file-export", "-", Sys.Date(), ".xlsx", sep="")
    },
    content = function(file) {
      GET(download_link_file(), write_disk(file))
    },
    contentType = "excel"
    
  }
  
)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.