0

I need to convert this assetUrl into a Blob file. I tried in this way:

    var dataUriToBlob = require('data-uri-to-blob');
    var assetBlob = dataUriToBlob(assetUrl);
    console.log("assetBlobTIPO", typeof assetBlob)

the console.log says assetBlob is NaN. Not sure it is correct.

Then i also need to convert the Blob file i get from the database into, back to a Uri file, so I can display it in my application when i click on it. Any solution?

aloisdg
  • 22,270
  • 6
  • 85
  • 105
mikerug88
  • 135
  • 8
  • Duplicate of [Uri to Blob & Blob to Uri in javascript](https://stackoverflow.com/questions/58064001/uri-to-blob-blob-to-uri-in-javascript) (posted yesterday by the same OP) – aloisdg Sep 24 '19 at 09:54
  • You wouldn't pass a url to `dataUriToBlob`, you'd pass something like a base64 encoded image to it (I think) – TKoL Sep 24 '19 at 09:56
  • @YongQuan the link is valid. Well it used to be `deleted by mikerug88 58 secs ago`. You cant see it because you dont have enough right. – aloisdg Sep 24 '19 at 09:56
  • Related to https://stackoverflow.com/questions/12168909/blob-from-dataurl , https://stackoverflow.com/questions/23150333/html5-javascript-dataurl-to-blob-blob-to-dataurl , https://stackoverflow.com/questions/14952052/convert-blob-url-to-normal-url , and maybe https://stackoverflow.com/questions/25046301/convert-url-to-file-or-blob-for-filereader-readasdataurl – aloisdg Sep 24 '19 at 09:57
  • Possible duplicate of [Convert Data URI to File then append to FormData](https://stackoverflow.com/questions/4998908/convert-data-uri-to-file-then-append-to-formdata) – Nam Tang Sep 24 '19 at 09:58
  • @aloisdg it was an old question without an answer, that's why i'm asking again. Anyway i already tried those solutions, but it didn't work – mikerug88 Sep 24 '19 at 10:05
  • @TKoL then how can i store an asset (like a pdf file) in a database and retrive it later on a next operation? – mikerug88 Sep 24 '19 at 10:07
  • Well how are you storing it now? – TKoL Sep 24 '19 at 10:08
  • And how does it come up to you to begin with? – TKoL Sep 24 '19 at 10:09
  • @TKoL the typeof returns it's a string, if i try to stringify then it returns " ". I'm not being able to store it because it's not a Blob – mikerug88 Sep 24 '19 at 10:33
  • @mikerug88 so let me try to understand: you're working on server-side code that should accept a file upload and store the file data in a database, is that right? And then, in a later step, you want to be able to read that file from the database and send it back as a response to a different request? – TKoL Sep 24 '19 at 10:37
  • @TKoL yes, right – mikerug88 Sep 24 '19 at 10:39
  • Is there a good reason why you want to store the file in a database rather than in a filesystem or in a purpose-built blob service, like Azure Blob Storage or Google Blobstore or something? – TKoL Sep 24 '19 at 10:41
  • @TKoL this is the code https://codesandbox.io/embed/kind-albattani-kx0fx?fontsize=14 – mikerug88 Sep 24 '19 at 10:46
  • Because that project requires it to be stored in a database. But if there's no solution, anything is accepted. – mikerug88 Sep 24 '19 at 10:47

0 Answers0