html5 FileReader , what kind of data readAsDataUrl function returns? is it url adress? or data itself?

吃可爱长大的小学妹 提交于 2019-12-10 18:15:27

问题


function readURL(input){    
    if(input.files && input.files[0]){
        reader.readAsDataURL(input.files[0]);
    }
    else {
        document.images[0].src = input.value || "No file selected";
    }
}
function checkSrc(){
    var src = document.getElementById('propertyImg').getAttribute('src');
    console.debug(src);
}
<input type='file' class='width70_prop' onchange="readURL(this);"></input>
<button onclick='checkSrc()'>check</button>

I am curious what kind of data FileReader's readAsDataUrl function returns.
When I checked src attribute via above code, it was look like
ridiculously giant long string(string begins something base-64 blah blah) .
I am wondering that string refers file's address or file itself.
any help will be appreciated. thx.


回答1:


It is the file itself, but base-64 encoded. It is also known as

Data Uris.




回答2:


It's the contents of the file encoded as Base64 string, suitable for use in a URL. See https://developer.mozilla.org/en-US/docs/DOM/FileReader



来源:https://stackoverflow.com/questions/12972110/html5-filereader-what-kind-of-data-readasdataurl-function-returns-is-it-url-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!