Javascript - get extension from base64 image

后端 未结 8 1706

I have a base64 encoded image returned from a service and it looks like this:

/9j/4AAQSkZJRgABAQEASABIAAD/4Yp2aHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWN         


        
8条回答
  •  清歌不尽
    2021-01-01 10:12

    A bit late but it seem the question was misunderstood. He just only had the base64 content of the image, not the full data URI.

    I wrote here for anyone who encounters with this quest, you can read the first character of content content.charAt(0). By base64 image content if the first char is:

    '/' : jpg

    'i' : png

    'R' : gif

    'U' : webp

    So for your case, it is 'jpg'.

提交回复
热议问题