K
K
kmvdev2022-04-18 15:55:23
JavaScript
kmvdev, 2022-04-18 15:55:23

How to pass pure base64?

when loading a JSON file in the input type file in event.target.result - a string like data:application/json;base64,ew0KICAiaGVhZGVyIjogew0KICAgICJsYXVuY2hwYWQiOiAiTGF1bmNocGFkIiwNCiAgICAicHJpc20iOiAiUHJpc20iLA0KICAgI is passed

how to remove this prefix data:application/json;???? to leave base64,ew0KICAiaGVhZGVyIjogew0KICAgICJsYXVuY2hwYWQiOiAiTGF1bmNocGFkIiwNCiAgICAicHJpc20iOiAiUHJpc20iLA0KICAgI

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MrColdCoffee, 2022-04-18
@kmvdev

test.replace(/^data:\w+\/\w+;/, '')
where test is your string

N
Nadim Zakirov, 2022-04-18
@zkrvndm

If you want to insert this base64 file into the input field, then you asked the wrong question, because removing the prefix will not help you here, and inserting is done in a completely different way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question