joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 770 forks source link

create / save file from blob #466

Open c-goettert opened 4 years ago

c-goettert commented 4 years ago

I am using a library to create a pdf-file locally (pdfmake). The library returns the generated pdf as a blob file. Can I use rn-fetch.blob to create a file from a locally created blob? According to the docs, the supplied fetch-methods can only be used for external urls, and the writeFile method only supports encodings utf8, base64, ascii and uri. I might be mixing things up a litte, but is it possible to create a local file from a locally created blob (in memory)?

841020 commented 4 years ago

@c-goettert you can create a local server to create file by pdfmake on local

pdfmake have a dev-playground dir dev-playground have server.js file

server.js provide api (url=http://localhost:1234/pdf, headers = {'Content-Type': 'application/json'}) your just need to make a form by pdfmake and do post your form to api you can get a base64 base64 have a header before a first comma you need to exclude it then you can decode leftover base64 to get pdf file finially you just need to save file

you need to install package.json

create local server command line example

node dev-playground/server.js
giioohbernini commented 3 years ago

Up!

Same problem here!! I already have a blob that was generated locally and I need to transform to save on the user filesystem!!

Any ideas?

fukemy commented 4 months ago

I can not download blob file with RNFetchBlob, eg: blob:https://abc.xxx/75387739-ef58-48eb-b6df-28ca5e4190ad