SoFunction
Updated on 2025-04-10

How to convert base64 images into URL format in JavaScript

1) Convert base64 image format to readable url format

Convert the image file to binary, and then convert the binary to url format through the URL createObjectURL function

   function getBase64URL(pic) {
        const blob = base64ImgtoFile(pic)
        const blobUrl = (blob);
        return blobUrl
    }

2) Convert the picture to a file

function base64ImgtoFile (dataurl, filename = 'file') {
        //Split base64 format: ['data:image/png;base64','XXXX']        const arr = (',')
        // .*?  Indicates that any character matches the next character that matches the criteria just matches:        // image/png
        const mime = arr[0].match(/:(.*?);/)[1]  //image/png
        //[image,png] Get the image type suffix        const suffix = ('/')[1] //png
        const bstr = atob(arr[1])   //atob() method is used to decode strings encoded using base-64        let n = 
        const u8arr = new Uint8Array(n)
        while (n--) {
            u8arr[n] = (n)
        }
        return new File([u8arr], `${filename}.${suffix}`, {
            type: mime
        })
    }

Summarize

This is the article about how JavaScript converts base64 images into URL format. For more information about base64 image conversion URL format, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!