Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react native file pdf to base64

import base64 from 'base64-js'
import {FileSystem} from 'expo'


function stringToUint8Array(str: string) {
    const length = str.length
    const array = new Uint8Array(new ArrayBuffer(length))
    for(let i = 0; i < length; i++) array[i] = str.charCodeAt(i)
    return array
}

export async function fileToBase64(uri: string) {
    try {
        const content = await FileSystem.readAsStringAsync(uri)
        return base64.fromByteArray(stringToUint8Array(content))
    } catch(e) {
        console.warn('fileToBase64()', e.message)
        return ''
    }
}

/* Accepts 'rawFile' file object or the data 'uri' */
export function fileToBase64Helper(rawFile: any, uri: string) {
    return fileToBase64(rawFile ? rawFile : uri)
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: mdn objects javascript 
Javascript :: leaflet limit map panning 
Javascript :: javascript neue zeilekill 
Javascript :: heroku 
Javascript :: How to print even and odd position characters of an array of strings in JavaScript 
Javascript :: operadores de asignacion javascript 
Javascript :: js spin wheel color 
Javascript :: how to send the value of the javascript variable value to my php page 
Javascript :: JavaScript built-in methods 
Javascript :: javascript Benefit of Using Symbols in Object 
Javascript :: zigale assefa 
Javascript :: pushing characters in vector javascript 
Javascript :: random number 1-3 
Javascript :: react destructuring with rename 
Javascript :: simple counter with react hook 
Javascript :: Multiply string using a for loop 
Javascript :: nodejs: express, morgan, mongoose package 
Javascript :: flip image on x axis phaser 
Javascript :: phaser place on rectangle 
Javascript :: phaser animation on stop event 
Javascript :: generate random email account javascript 
Javascript :: chai promise resolved 
Javascript :: nodejs: send html file to show in Browser 
Javascript :: mogoose schema to add json as a property 
Javascript :: javascript replace all with variable 
Javascript :: js index of 
Javascript :: react native toggle button with text 
Javascript :: how to initialize an array in javascript 
Javascript :: how to change class by is in js by toggle 
Javascript :: turn string into number javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =