Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file name from base64 string

Tags:

javascript

I have base64 decoded file as follows:

"data:application/vnd.openxmlformats-officedocument.wordprocessingml.document;base64,UEsDBBQABgAIAAAAIQBXw9vwrQEAAOEJAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADElttqwkAQhu8LfYewt8WsWiilGL3o4bIVah9gzU502+yB3fH09p0YDUXUSDV4I8TZ//+/mQ1heoOlzqM5+KCsSVgnbrMITGqlMpOEfY3eWo8sCiiMFLk1kLAVBDbo3970RisHISK1CQmbIronzkM6BS1CbB0YqmTWa4H06CfcifRHTIB32+0HnlqDYLCFh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2iaIVroUfG/4rAcI2bBVhFPS7tHiPsa2UWyDTUixchhT+0rJsRU2eksjrtGYtRRxuTooC0VnJwhnO+R6H9METYOSKPIVtgleLad/JCyyUKBu1KYU55+ywNN8sBcvbAk8M2Jr6+rOhbSxscTsA58vNjkJJH5eeJcTSjIi1ijJgj4e9vDkqml6/5XGomyY2/fQyQ/Asw+8uK82ShMieauIy2068jq+0iH2D1RZ4ezV0m5rmkBv9AxdLdXoOlLxIVYckCzHrQXmuywe5mcHmdGmrpLs9Isr2PHx6+fied1fM331pv+wetKXbQ/FdGUO99crNKRtOWF7SSfrLT0X/abnj…"

That is this file:

enter image description here

Is there any easy way to get the file name from the base64 string using only javascript?

like image 844
Boky Avatar asked Nov 28 '17 07:11

Boky


People also ask

Can we get file name from base64 string?

Well, no... the base64 string doesn't contain the file name, only the contents of the file. If you want to keep the filename, you're going to have to store it some other way. It's already available on the file object you have shown us, you'll just have to store it in a reasonable manner for whatever your use-case is.

How do I identify a file type by base64 encoded strings?

If you have a base64 string you can detect file type by checking the first character of your base64 string: '/' means jpeg. 'i' means png. 'R' means gif.


1 Answers

Well, no... the base64 string doesn't contain the file name, only the contents of the file.

If you want to keep the filename, you're going to have to store it some other way. It's already available on the file object you have shown us, you'll just have to store it in a reasonable manner for whatever your use-case is.

like image 195
Shadow Avatar answered Oct 18 '22 22:10

Shadow