capacitor unable write blob to file and read it back - ionic-framework

I'm trying to write a blob from fetch to a file using capacitor Filesystem.writeFile
when I write the file this is the data I write:
...etc (you get the point full png file as a blob)
but when I read the data this is ALL the data returned
{data: "ZumJPw=="}
Any idea what's going on? How do I fix it?

Related

how to read and write (update) the same file using spark (scala)

I want to update a CSV file depending on some condition, for that I read the file, made all the needed update, however when I tried to write it I'm getting a FileNotFoundException.
I think that it is due to the writing process, because when I access the path (where the input/output file were located) I find it empty.
Is there a better way to update a file? And if not, how can I resolve the FileNotFoundException error?
you can do it either by writing a temporary table/csv or using checkpointing :
This works :
sparkSession.sparkContext.setCheckpointDir("tmp")
ss.read.csv("test.csv") // read existing csv
.withColumn("test",lit(1)) // modify
.checkpoint(eager = true) // checkpoint, write to disk
.write.mode("overwrite")
.csv("test.csv") // write to same location

How to download a file (csv.gz) from a url using Python 3.7

As with others who have posted in the past, I cannot figure out to download a csv.gz file from a URL in Python 3.7. I see posts but they only post a 2kb file.
I am a 100% newbie using Python. What follows is the code for one file that I am trying to obtain. I can't even do that. The final goal would be to request all files that start with 2019* using python. Please try the code below to save the file. As others stated, the file is just a name without the true content - Ref: Downloading a csv.gz file from url in Python
import requests
url = 'https://public.bitmex.com/?prefix=data/trade/20191026.csv.gz'
r = requests.get(url, allow_redirects=True)
open('20191026.csv.gz', 'wb').write(r.content)
Yields:
Out[40]:
1245
I've tried "wget" and urllib.request along with "urlretrieve" also.
I wish I could add a screenshot or attach a file. The file created is 2kb and not even a csv.gz file. But the true file that I can download from a web browser is 78mb. The file is 20191026.csv.gz not that it matters as they all do the same thing. The location is https://public.bitmex.com/?prefix=data/trade/
Again, if you know of a way to obtain all the files using a filter such that 2019*csv.gz would be fantastic.
You are trying to download the files from https://public.bitmex.com/?prefix=data/trade/.
To achieve your final goal of download all the files starting from 2019* you have to do in 3 steps
1) you read the content of https://public.bitmex.com/?prefix=data/trade/
2) convert the content into an list, from that filter out the file names which starting from 2019.
3) from the result list try to download the csv using the example which you referring.
Hope this approach will help you
Happy coding.

How to load an SVG and a referenced PNG from a REST service at the same time?

I'm trying to create a web service in PHP that can deliver an SVG with reference to a PNG raster image. Both the data for the SVG as well as the binary PNG image come from a MySQL database on the server.
Option A: Encode the PNG data in base-64 and embed it directly in the SVG, such as:
<image xlink:href="data:image/png;base64,..."/>
Concerns: 30% heavier load than loading it as pure binary and noticeable delay when loading it with Postman (or is this just because of Postman).
Option B: Call the PNG data as binary and save it as a file on the file system, then call the SVG file, which would then reference the physical PNG file.
Concerns: Involvement of the file system (which implies I need to start managing physical files, expiration dates etc).
Is there perhaps another way that an SVG can reference the binary data on the fly without it having to be on the file system?
To accomplish something similar (in my case sending data for SVGs with additional data about each file as binary files, which are much smaller than sending xml, text, or json) - I use CBOR. In my case, I compress the SVG using LZString compression first, and add this along with additional data attributes to a JSON object. Then I convert the JSON object to CBOR. I think CBOR can handle your base 64 data without any need for conversion - more information about it is here: cbor.io
I found a PHP library for CBOR here: https://github.com/2tvenom/CBOREncode
This may not be the way to go at all for you, but I thought I'd throw it out there just in case.

How to load "file like object", instead of filename, with kivy SoundLoader?

I need to play a mp3 file from gridfs in mongodb. I will get a file-like object instead filename (to the system disk).
I cannot find anyway to use SoundLoader to play the file like object directly. I checked the code here https://kivy.org/docs/_modules/kivy/core/audio.html. it seems that kivy audio does not suppot it. Am I right? I mean, like wave module, you can open it with file like object. I prefer not to use wave because it may has issues in different OSs.
wave.open(file[, mode])
If file is a string, open the file by that
name, otherwise treat it as a seekable file-like object.
Any other way to load the data to SouldLoader instead of filename? Many thanks.
This may not be a direct answer but could be an alternative for now. I can use GridFSBucket in GridFS to download the file in stream then save temp file to disk. Finally load by SoundLoader. With this way, it would solve the problem with large media file issue. This solution also works for image or video but require some disk storage of course.

How to save streaming data to Matlab .mat file

I am trying to save real-time streaming data obtained from hardware to Matlab workspace, I use the following command: My issue is, it only saved the last set of data, but not all data.
To save all variables from the workspace in binary MAT-file, test.mat, type
save test.mat
When I tried with this
save('test.mat','-append'); ,
it makes my program halt, so I would like to know what is the correct way to achieve this?
They have same name and they are constantly overwritten, I did not get error message, I still get the file saved but I noticed that it only showed the latest set of data, what should I do to avoid this? I want it to save every set at each time step
The correct syntax for appending using save is
save(filename,variables,'-append')
This will save append all new variables and overwrite variables already in the filename.mat with the updated values.