0

I'm a new one in angular and ionic and writing test application. I'm trying to implement something like "PhoneBook". I've added some default data with images (avatar) and want to realize adding new contact right now. The problem is I don't know how to save a new image to application folder (I don't have any server). Specify, I contain my json data in local browser storage and there is one field which contains name of image. In my view I do as follow:

<ion-item class="item item-avatar item-remove-animate" ng-repeat="contact in contactIndexCtrl.contacts | filter: contactIndexCtrl.search track by contact.id"
    ui-sref="root.contact-detail(::{ id: contact.id })">
        <img ng-src="./img/{{::contact.pic}}"> 
...
</ion-item>

So the question is how to upload new images to img folder?

1 Answer 1

1

You can't save files to the img/ directory inside the project. You can understand why reading about how cordova apps work.

Your options are:

  • Save the image as a binary or Base64 into Storage, for that you can use LocalStorage (10mb limit, so not a good option), or a SQLite dataBase (Alternativelly there are some DB implementations other than SQLite ngCordova plugin such as LocalForage ou CouchDB)

  • Save the image to your app sdCard directory using Cordova FilePlugin

Here are some references so you can take a look and decide which is good for you. For your case I wold go with Base64 storage to SQLite DB

https://dbwriteups.wordpress.com/2015/09/19/saving-images-to-app-storage-in-ionic-using-ngcordova/

https://github.com/mozilla/localForage

https://devdactic.com/complete-image-guide-ionic/

http://gonehybrid.com/how-to-use-pouchdb-sqlite-for-local-storage-in-your-ionic-app/

https://github.com/mozilla/localForage

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.