Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
Convierta la cadena base64 en un archivo Object JS

Necesito guardar un archivo JS en la base de datos y luego recuperar este archivo.

Al guardar el archivo y convertirlo a string base64, ¿cómo leo este archivo base64 y lo vuelvo a convertir al formato original (archivo JS)?

Estoy guardando en la base de datos con axios como este:

 let formData = new FormData(); formData.append('file', file); const create = (formData, onUploadProgress) => { return http.post( '/api/v1/maps/upload', formData, { headers: { 'Content-Type': 'multipart/form-data', }, onUploadProgress, } ); };

Archivo original:

 export default { label: "Test file JS", viewBox: "0 0 800 1120", locations: [ { id: "01", path: "M 445.73 747.67 205.6 533.44 574.22 1 797.73 195.63 799 204.74 535.49 492.74 591.82 587.22 445.73 747.67 Z" }, { id: "02", path: "M 1 818.38 203.08 530.9 443.39 749.75 105.29 1119.38 1 818.38 Z" } ] };

Archivo recuperado de la base de datos base64:

 ZXhwb3J0IGRlZmF1bHQgewpsYWJlbDogIlRlc3QgZmlsZSBKUyIsCiAgdmlld0JveDogIjAgMCA4MDAgMTEyMCIsCiAgbG9jYXRpb25zOiBbCiAgICB7CiAgICAgIGlkOiAiMDEiLAogICAgICBwYXRoOgogICAgICAgICJNIDQ0NS43MyA3NDcuNjcgMjA1LjYgNTMzLjQ0IDU3NC4yMiAxIDc5Ny43MyAxOTUuNjMgNzk5IDIwNC43NCA1MzUuNDkgNDkyLjc0IDU5MS44MiA1ODcuMjIgNDQ1LjczIDc0Ny42NyBaIgogICAgfSwKICAgIHsKICAgICAgaWQ6ICIwMiIsCiAgICAgIHBhdGg6ICJNIDEgODE4LjM4IDIwMy4wOCA1MzAuOSA0NDMuMzkgNzQ5Ljc1IDEwNS4yOSAxMTE5LjM4IDEgODE4LjM4IFoiCiAgICB9CiAgXQp9Ow==

¡Convertidor aquí!

Gracias por tu ayuda

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Para decodificar base64 en una cadena, deberá usar atob .

 <html> <body> <script id="output" type="module"></script> <script type="module"> const content = atob("ZXhwb3J0IGRlZmF1bHQgewpsYWJlbDogIlRlc3QgZmlsZSBKUyIsCiAgdmlld0JveDogIjAgMCA4MDAgMTEyMCIsCiAgbG9jYXRpb25zOiBbCiAgICB7CiAgICAgIGlkOiAiMDEiLAogICAgICBwYXRoOgogICAgICAgICJNIDQ0NS43MyA3NDcuNjcgMjA1LjYgNTMzLjQ0IDU3NC4yMiAxIDc5Ny43MyAxOTUuNjMgNzk5IDIwNC43NCA1MzUuNDkgNDkyLjc0IDU5MS44MiA1ODcuMjIgNDQ1LjczIDc0Ny42NyBaIgogICAgfSwKICAgIHsKICAgICAgaWQ6ICIwMiIsCiAgICAgIHBhdGg6ICJNIDEgODE4LjM4IDIwMy4wOCA1MzAuOSA0NDMuMzkgNzQ5Ljc1IDEwNS4yOSAxMTE5LjM4IDEgODE4LjM4IFoiCiAgICB9CiAgXQp9Ow=="); console.log(content); const body = document.body; const script = document.getElementById("output"); script.text = content; script.src = "content.js"; //import * as example from "./content.js"; //console.log(example.locations); </script> </body> </html>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda