question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Base64 string for source?

See original GitHub issue

Hi, can the source take a base64 string for the URI? I know <Image /> can. Was wondering if this had the same capability.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

11reactions
ryemcccommented, Sep 4, 2018

You can write the Base64 encoded content to a file using react-native-fs, naming the file xxxx.mp4. Then pass the Video component the path as the uri, prefixed with ‘file://’.

import RNFS from 'react-native-fs'
const downloadToFile = (base64Content, contentId) => {
	const path = `file://${RNFS.DocumentDirectoryPath}/${contentId}.mp4`
	RNFS.writeFile(path, base64Content, 'base64')
	.then(success => {
		console.log('FILE WRITTEN: ', versionId)
	})
	.catch(err => {
		console.log('File Write Error: ', err.message)
	})
}

Then in the video component, you can retrieve the file by its contentId:

<Video source={{ uri: `file://${RNFS.DocumentDirectoryPath}/${contentId}.mp4`}} />
3reactions
hadrienbbtcommented, Nov 7, 2017

Hello, did someone find a way to play base64 encoded videos ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Base64 - Wikipedia
In computer programming, Base64 is a group of binary-to-text encoding schemes that represent binary data in sequences of 24 bits that can be...
Read more >
Source code - Apache Commons
Objects; 023 024/** 025 * Provides Base64 encoding and decoding as defined ... 143 * 144 * @param base64String String containing Base64 data...
Read more >
Does anyone know how to decode and encode a string in ...
Receive the base64; Decode the base64 to bytes using the Base64 class; Decode the bytes to a string (e.g. new String(bytes, encodingName) )....
Read more >
How To Encode and Decode Strings with Base64 in JavaScript
In JavaScript, it is possible to use Base64 to encode and decode strings. ... Build applications, host websites, run open source software, ...
Read more >
How to Display Base64 Images in HTML - W3docs
Base64 encoding and Data URL go hand-in-hand, as Data URLs reduce the number of HTTP requests that are needed for the browser to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found