HTML5 File API: get File object within FileReader callback

后端 未结 2 1263
猫巷女王i
猫巷女王i 2020-12-14 19:25

With the new File API in Javascript you can read files in Javascript to create dataURLs to show clientside pictures clientside. I\'m wondering if you can reach the File obje

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-14 20:08

    I already found a way. Maybe not better than the scope wrapper, but I think it's neater:

    for ( var i=0; i

    There is now a much easier (apparently faster) way (sync!) to get a file's data URL:

    img.src = URL.createObjectURL(file);
    

    Demo on http://jsfiddle.net/rudiedirkx/ZWMRd/8/show/ of both methods, and the original problem illustrated (drag multiple images and check the title tooltips).

提交回复
热议问题