I'm trying to create a file preview system.
When the user click in a upload button and select files, I use the HTML5 FILE API to get all the file info and create a thumbnail for the file.
The user can cancel the upload of some of thoose files and add more files too.
What I have now is this:
<p><input id="blob" name="blob" type="file" size="75" multiple /></p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input id="blobtype" name="blobtype" type="text" size="20" />
<input id="bloburl" name="bloburl" type="text" size="50" />
<input id="salvar" name="salvar" type="submit" value="salvar" />
</form>
<p id="result"></p>
And my javascript:
function cbu(file)
{
if (window.URL){ return window.URL.createObjectURL(file);}
else if (window.webkitURL){ return window.webkitURL.createObjectURL(file);}
else if (window.createObjectURL){ return window.createObjectURL(file);}
else if (window.createBlobURL){ return window.createBlobURL(file); }
}
document.getElementById("blob").onchange = function(event)
{
var result = document.getElementById("result");
var i = 0, j = event.target.files.length;
for (i = 0; i < j; i++)
{
var url = cbu(event.target.files[i]);
var img = document.createElement("img");
img.onload = function(){ }
result.appendChild(img);
img.src = url;
document.getElementById("blobtype").value = event.target.files[i].type;
document.getElementById("bloburl").value = url;
}
};
It genarate a thumbnail like this:
<img src="blob:b9a8e310-05b3-48ba-ba24-9ca7cf287f71">
This value blob:b9a8e310-05b3-48ba-ba24-9ca7cf287f71
is send to a PHP file when user submit the form.
So my question is, how can I transform this blob url into a file so I can save it in my app?
There is a better way of doing this?
Thank for your help!
See Question&Answers more detail:os