Download generated Blob with Ionic 3 into Android Device - android

I have encounter this issue recently while using Ionic3 to develop app on Android phone. I have cols and rows of data which I extracted into a 2D array. After which, I create a csv blob from the 2D array using papaparse.
let csv = papa.unparse({
fields: this.headerRow,
data: this.csvData
});
var blob = new Blob([csv]);
var a = window.document.createElement("a");
a.href = window.URL.createObjectURL(blob);
a.download = "confidentialData.csv";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
The code above works only for browser download, when I load it into my android phone, it does not download at all. I have read many other posts on how Ionic app download file into the device using FileTransfer and File. But I cant seem to work around with these because FileTransfer.download requires a url source in order to download the file into the device.
But for my case, the file is not hosted anywhere and the blob is generated dynamically from my code. Would appreciate any help or recommendation on how I can download my csv blob into my android device using Ionic 3. Thank you very much.

You are getting it wrong. FileTransfer works as an upload or download from an url (For example uploading a picture to a server from your device or downloading a picture from the server to your device).
What you want to look at is Cordova File and use the functions createFile and writeFile to save the data on the device.
EDIT: To save your file on the Documents or Downloads folder you will need to use cordova.file.externalRootDirectory + '/Download/' for it to work, also take in mind that a lot of folders are just read only (dataDirectory on iOS for example)
Hope this works.

Related

Displaying images on running website on android mobile application

I have a running website where i have images of products uploaded in a directory and the respective
images name in mysql database. Now, i have my mobile application (android) connected to my running website
database through an API that does the communication.
Technology used for my application development
1. Android Studio (IDE)
2. Retrofit for communication with the Slim
3. Slim for the API
4. Mysql for storage
ISSUES
Product upload is only allowed on the website.
How can i have access to the product images in the image folder of my running website to be displayed
on my android app through the API. Am only having access to the image name which was stored in the
database after product upload on my website.
Am i to have the whole image content uploaded in database using BLOB when uploading product on my
running website.
Please, kindly assist me in resolving this.
THANK YOU.
You don't want to store an image in the database as BLOB, now you are getting the file name using the API and you know the file stores server path, then you can achieve those images like this.
Here am using picasso image library to set your images to ImageView in android , you can use different tricks to set image.
String filename = "yourProductImageName.png" //this is the filename you get from api
String filepath = "https://yourDomin.com/imagesdirectory/" + filename;
Picasso.get().load(filepath).into(imageView);

Displaying images from dataDirectory in ionic2

I'm working on an app, using ionic2.
I'm storing a set of images that I downloaded from the server in the dataDirectory to save mobile traffic when the app is used without wi-fi.
Now, I would like to display them inside my template.
Is there a recommended way how the image should best be inserted?
I tried giving the ion-img or img-tag
the complete path (file.dataDirectory + “myImg.jpg” -> "file:///data/user/0/io.ionic.starter/files/myImg.jpg”
(stored in my imgPath variable, the path is written after the platform.ready event), but only a broken image symbol is shown. When accessing images from my assets folder I do not encounter any problems, but how can I access the dataDirectory’s images?
<img width=“200” height=“200” [src]=“imgPath” *ngIf=“imgPath”>
Or do I have to read each image from the dataDirectory and store them in a local variable as a base64 string?
There are many reason for showing broken image in IONIC.
If you are using live reload then sometime images are shown as broken image. You can run directly to see if it resolves your issue.
If you want to use base64 image, either you can save it SQLite or in local variable which may resolve your issue.

Read video file with cordova in android

Currently I am working on an Ionic Cordova app which let an user upload vdo and image from android device. I finished working image upload with help of cordova camera plugin which can choose photo from user phone and return base64 data. Now i am trying to get video as i did for image. But the video return data is file url which is sth like this content://com.android.providers.media.documents/document/video%3A27227 . I don't know how to continue .
Appreciate your help
You can use that url and pass it to a fileHandler routine and read the contents of the video.
I will forewarn you that it gets very complicated with iOS and Android using different file url formats. And there's no consistency between various Android devices that I ended up using a 3rd party plugin from the Ionic market place which is worth every penny and saved me months of development time and aggravation.

How to clear temporary data (storage) inside of a cordova project?

I am using cordova 3.5 and eclipse to develop a mobile application. Inside of an image stream I am downloading 30 images through jquery append (url). The storage information are displayed in the following figure.
Anyone knows how to clear the "DATA" (19.41MB) category programmatically?
I have the same issue with IOS, when I try to follow apples data storage guidelines...
best
M

How to get http url of downloaded file in android?

I am trying to find a way to get http-url of downloaded file in android. Is there anyway to do it ?
I have looked around DownloadManager, but it seems not appropriate for this scenario.
e.g. if we open browser with link : http://www.xyz.com/myapp.apk?param1=abc
and now after downloading and installing apk.
In same application (when it starts) I need to get -> param1=abc.
Any kind of help will be appreciated!
Thanks
Personnaly, I think that the downloaded url is not stored in the .apk file. The apk file is a portable file and can be downloaded from different url addresses and the web browser will not add a metadata to the apk file.

Categories

Resources