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.
Related
I am trying to create an app that will be able to display a pdf file in the app itself. I'm currently using the Xamarin.Bindings.PDFView-Android by SIDOVSKY which works really nicely. I can open a file easily from the assets... what I'm struggling to do is open a file from the internet.
Just a single line of code:
FindViewById<PDFView>(Resource.Id.pdf_view).FromAsset("report.pdf").Show();
Is enough to display a PDF that can be pinched to zoom which is great. However, I now want to access a file stored on the local network. Either using a SMB share, or through the intranet. Whichever way I try I can't figure it out.
There is a .FromFile setting, but I can't get it to work by putting a smb path in here. Is there a way to convert this? Or must I download the file to the local device first?
Thanks
Andrew
I'm trying to find simplest solution to make app where I can download all the images from the specifed, hardcoded directory.
So far, my idea is to get list of all .jpg images (since it will be the only image format in this directory) and put it in places on ViewPager so each image will be on seperate page.
Anyone has nice snippet or friendly library to use to make it happen?
You can create a txt file on the server in which the URLs of all images will be kept; then program your app to download this file first; then use input stream to read the URLs from the file and create a loop to download all urls until they finish, by checking if the input is null.
On server side either add the urls manually to the file or write a JavaScript to automatically write the URLs when uploading the image.
I try to load an image file from the phone. And by using the example code (Camera.sourceType = Camera.PictureSourceType.PHOTOLIBRARY), when a button is pressed, a popup showing that I can select to open "Photo Library" OR "File Manager" (some names like that, may differ across phone models and languages). I can get the returned image file if I select it via Photo Library (as the code indicated?), but failed if I use "File Manager". The error is saying "Unable to load local resources - file://....". (In contrast, the returned value from Photo Library is of the content:// protocol).
Since users may randomly use one of the applications (and some images are not in photo library scope), how can I get it correct with both ways?
=======Update========
Just realize that the error is reported because I use the returned file handle to the image as the image source. And my phonegap app use a remote link as index.html, which is thus not allowed to load local resources (cross-domain issue).
So I need to upload it at background firstly and set the image source to the returned url instead...
Just as I updated, I use a remote page (e.g., http://domain.com/index.html) instead of a page in assets (e.g., index.html, in most PhoneGap documents and tutorials). So the file:// protocol will meet cross-domain restrictions and cannot be loaded by the remote page. While the content:// protocol has no such restrictions. I have to reorganize the architecture of my solution.
i wanna display image saved on the D://foldername//foldername//filename from my computer on the android emulator using eclipse and also how to display it from a server?
as i am accessing the data from the server and also the images are saved on the server
Unless you're running a web server which provides public access to the image, I don't think you can display an image from your computer using a path like that. You either need to include the image in the assets or res/drawable folders within the app, or have the image accessible through a web server which you can load from within the app using the method described in this question.
The question I have is simple but hard to put in words, I'll give it a try anyways.
I am trying to load a web page in webview. However, the load time is a little bit too high.
Is there any way I can put the images in the assets folder and load them from there instead?
If not, is there a way I can load the whole site from the assets folder, providing that my PHP files can still communicate with my internet database?
I have already read most tutorials, but those are pretty vague when it comes to concrete help.
try this... WebView with custom HTML and local images
There is no way to store your php files on the device itself. They need a server to execute them and sent the result to the device if the are on the device you would just show the php code to your webview and that would certainly not work.
The Webview should be able to cache some of the images itself. But it seems that there is no way to access images from the sd card or the internal storage from your webview.
Maybe it is possible to store some of your data through html5 local storage apis but I don't have any expertise on that.
Sure ! you can do it. Just install AndroPhp it is a localServer for Android.
Locate you project than on your device under the www/ folder. If you have a DB also just import your .sql trough phpmyadmin.
on Android side call you project 127.0.0.1:8080/yourProject
Thats All!