我希望能够采用 base64 编码的字符串并模仿它,就好像它是我从“浏览”功能中选择的文件一样。这是一个简短的例子:
<input type="file" id="file" />
<script>
//I want to be able to access it here
$("#file").files;
</script>
我希望能够访问 files 数组并将其用作普通文件。我目前得到base64编码的字符串,如下所示:
// resize the canvas and draw the image data into it
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height);
preview.appendChild(canvas); // do the actual resized preview
var base64String = canvas.toDataURL("image/jpeg", 0.7);