fuctBase64
Convertendo uploads de arquivos para Base64
Usando a biblioteca.
Instalação
instale a biblioteca usando
npm install fuctbase64
ou
npm install fuctbase64 --save
para salvar em seu package.json.
Uso
Em Angular 2+
// Imports
import { Component } from '@angular/core';
let fileUpload = require('fuctbase64');
// Component Decorator
@Component({
selector: 'app-file-upload-to-base64',
template: `<input type="file" name="fileInput" (change)="onFileChange($event)" #fileInput formControlName="fileUpload" />
<br>
<div>
{{fileResult}}
</div>`
})
// Component Class
export class FileUploadToBase64Component {
title = 'app works!';
fileResult: any;
constructor(){
}
onFileChange(event){
let result = fileUpload(event);
this.fileResult = result;
}
}
Confira o Plunkr
Em Vanilla Javascript
<input id="the-file" name="file" type="file">
let fileUpload = require('fuctbase64');
var fileInput = document.getElementById('the-file');
let fileResult = fileUpload(fileInput, true);
console.log(fileResult);
Upload de vários arquivos
<input id="the-file" name="file" type="file" multiple>
let fileUpload = require('fuctbase64');
var fileInput = document.getElementById('the-file');
let fileResult = fileUpload(fileInput, true);
console.log(fileResult);