Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8459027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:14:09+00:00 2026-06-10T13:14:09+00:00

Base64 encoding of images is a really cool little feature in R Studio Markdown

  • 0

Base64 encoding of images is a really cool little feature in R Studio Markdown that creates all in one HTML pages that are easy to distribute or share. No need to worry about having the image as a seperate file. The browser knows what to do with it.

I’d like to extend this functionality to encoding CSV files as well. Looking at how they are doing it now, it looks like they are passing the information to .Call and using C/C++ to encode the file information.

From (line 177, and 192) : https://github.com/rstudio/markdown/blob/master/R/renderMarkdown.R

.b64EncodeFile <- function(inFile)
{
   fileSize <- file.info(inFile)$size

   if (fileSize > 0){
      paste( "data:", .mimeType(inFile),";base64,",
         .Call(rmd_b64encode_data,readBin(inFile,'raw',n=fileSize)),
         sep='')
   } else {
      warning(inFile,'is empty!')
      inFile
   }
}


.b64EncodeImages <- function(html)
{
   reg <- "<\\s*[Ii][Mm][Gg]\\s+[Ss][Rr][Cc]\\s*=\\s*[\"']([^\"']+)[\"']"
   m <- gregexpr(reg,html,perl=TRUE)
   if (m[[1]][1] != -1)
   {
      .b64EncodeImgSrc <- function(imgSrc)
      {
         inFile <- sub(reg,"\\1",imgSrc)
         if (length(inFile) && file.exists(inFile))
            imgSrc <- sub(inFile,.b64EncodeFile(inFile),imgSrc,fixed=TRUE)

         imgSrc
      }
      regmatches(html,m) <- list(unlist(lapply(regmatches(html,m)[[1]],.b64EncodeImgSrc)))
   }

   html
}

Now, how do I accomplish the same thing, with a CSV file? Importantly, how do I get the browser to understand it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:14:11+00:00Added an answer on June 10, 2026 at 1:14 pm

    If I read your intentions right, if you make an A element with the encoded data in the HREF attribute, then clicking on the link will get the file. Just tested this with an encoded image block I had lying around:

    <a href="data:image/jpeg;base64,[blah blah blah]">Click Me</a>
    

    So as long as you set the mime type (text/something?) all you need do is construct that element and stick it in your HTML file. User clicks link, file download starts, from its embedded base64 encoding. Sorted. Complete example with a missing mime-type which just lets the browser read it:

    <html>
    <head>
    </head>
    <body>
    <h1>Test</h1>
    <a href="data:;base64,aWQsbmFtZSxhZ2UKMSwiRnJlZCBGb28iLDk5CjIsIkpvZSBCbG9nZ3MiLDIyCg==">click me</a>
    </body>
    </html>
    

    Where that data string has come from:

    > markdown:::.b64EncodeFile("test.csv")
    [1] "data:;base64,aWQsbmFtZSxhZ2UKMSwiRnJlZCBGb28iLDk5CjIsIkpvZSBCbG9nZ3MiLDIyCg=="
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know .net supports base64 encoding of byte arrays. But i thought that i
I have been working with base64 encoding. I have successfully encoded images to NSString
I receive some xml-files with embedded base64-encoded images, that I need to decode and
I have a question about base64 encoding for images. I used base64 for small
How to get all images from a specific website and replace them with base64
Does IE 9 support Base64 image encoding?
I want to display image using base64 encoding in IE using GWT If it
I have the following text: --------------030805090908050805080502 Content-Type: image/jpeg Content-Transfer-Encoding: base64 Content-ID: <part16.07030906.00090703@highcontrast.ro> /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAA /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAARgAA/+4ADkFkb2JlAGTAAAAA
Can base64 encoding applied to multibyte utf-8 characters ? How base64 encoded string is
I'm using MD5 function and Base64 Encoding to generate a User Secret (used to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.