i do have question, i have a PDF file fetched in my server which returns a resource location URL, I want to convert it to base64 how do i do that? thank you
Asked
Active
Viewed 85 times
-2
-
You want to convert what to base 64? The PDF?? Or the URL? I don't exactly understand your question. – Cullub Nov 17 '16 at 03:03
-
the PDF sir cullob – james managbanag Nov 17 '16 at 03:14
-
Which language are you planning to use? Do you have the path stored in the database or just in the filesystem? – Manuel Azar Nov 17 '16 at 03:16
-
the path is from aws server for example "location: www.aws.com/pdf.file" and i want to do it inside angularjs controller – james managbanag Nov 17 '16 at 03:22
-
1`fetch(url).then(response => {return response.blob()}).then(blob => {let f = new FileReader(); f.onload = doSomethingWithDataURL; f.readAsDataURL(blob);});` `function doSomethingWithDataURL(evt){let dataURL = evt.target.result; ...}` or you could use xhr + `responseType = 'blob';` for ES5 browsers. Oh and you'll have to configure your aws so that it accepts cross-origin requests from your domain. – Kaiido Nov 17 '16 at 04:06
-
Possible duplicate of [How can you encode a string to Base64 in JavaScript?](http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript) – Martin Tournoij Nov 17 '16 at 09:48
1 Answers
0
I hope this can help you
btoa('www.aws.com/pdf.file') //"d3d3LmF3cy5jb20vcGRmLmZpbGU="

ywDing
- 61
- 2
-
i have other question why other URI starts with "data:application/pdf;base64"? – james managbanag Nov 17 '16 at 04:27