I have created Object url of PDF file using url: URL.createObjectURL(file[0]).
e.g url = blob:http://0.0.0.0:5002/e468fb70-d597-4b17-bb3a-ec6272f2d7fe.
Now what I want to do is, read pdf from url=blob:http://0.0.0.0:5002/e468fb70-d597-4b17-bb3a-ec6272f2d7fe and create file object like
File(61)
{
name: "ICT_zbbihfc_dummy.pdf",
lastModified: 1548148972779,
lastModifiedDate: Tue Jan 22 2019 17:22:52 GMT+0800 (Singapore Standard Time),
webkitRelativePath: "",
size: 61,
type: "application/pdf",
webkitRelativePath: ""
}
This is in Javascript.
To convert Blob object url of PDF or Image to File object
var file_object = fetch('blob:http://0.0.0.0:5002/e468fb70-d597-4b17-bb3a-ec6272f2d7fe')
.then(r => r.blob())
.then(blob => {
var file_name = Math.random().toString(36).substring(6) + '_name.pdf'; //e.g ueq6ge1j_name.pdf
var file_object = new File([blob], file_name, {type: 'application/pdf'});
console.log(file_object); //Output
});
//-------
To convert Base64 of Image to File object
var file_object = fetch('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAA')
.then(r => r.blob())
.then(blob => {
var file_name = Math.random().toString(36).substring(6) + '_name.jpeg'; //e.g ueq6ge1j_name.jpeg
var file_object = new File([blob], file_name, {type: 'application/jpeg'});
console.log(file_object); //Output
});
//-------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With