如何从Golang中的base64编码文件中提取文件扩展名?

I want to allow users to upload files as base64 encoded. The results are like:

data:image/jpeg;base64,/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kA...

or

  data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAfAAAAAXNSR0IArs4c6QAAAARnQU...

So I'm wondering what is the idomatic way to extract the file extension from the encoded file strings?

It's simple enough to use string/byte functions to extract the mime type — i.e., the part between data: and ;base64.

Then you can use the standard mime package to get the extension from the type:
https://golang.org/pkg/mime/#ExtensionsByType

There is a good golang package seems to be there on github https://github.com/vincent-petithory/dataurl that gives whole information about a base64 image URI string.