Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

Save ,retrieve and upload data to a remote server

$
0
0

I took a look at your code.

First, you aren't using anything for storage. As bengtler mentioned, I would look into PouchDB.

Here is a good tutorial for doing that:

http://devgirl.org/2014/12/30/sync-data-using-pouchdb-in-your-ionic-framework-app/

I'm not really seeing anything "wrong" with your code. Just you aren't saving it anywhere.

You have the right format for getting the pictures, the camera will return the image in base64 encoding.

What you need to do next is save this base64 (pictureURL in your code) to a DB.

I would work on getting PouchDB or another backend setup for the project. I made the mistake in saying to use localstorage. Again bengtler is correct that localstorage should not be used for images, since they will take up all your storage space. It works well for me when I need to save a few small strings, like username.

I've had much luck with uploading images to Parse via their file api, as well as with AWS S3. If you need help getting started, let me know.)

Quick example for Parse:

  1. Initailize Parse for your app. (https://blog.nraboy.com/2015/04/use-parse-core-in-ionic-framework-mobile-apps/)

  2. (Optional) User logs in. This way you know what user uploads what image and you can retrieve their images.

  3. User takes photo. (you got that part down!)

  4. Upload photo to Parse via their File API. (I can't remember if parse accepts base64 uploads for images. If not, change the camera.destinationType from Camera.DestinationType.DATA_URL to Camera.DestinationType.FILE_URL, which will return the actual file location on the device.)

  5. The file upload returns a URL of where the file/image is saved on their server. Don't lose this, as there is no way to retrieve it.

  6. Save this url to the user object on parse. You could create an array on the parse user object called Images, and you would just push the url to that array. You could also save this URL to localstorage, though I wouldn't recommend that as sometimes localstorage can get cleared and you won't have their image URLs any more.

  7. (Optional) When a user logs in successfully, if you are using parse, you will get back their entire user object which will have their images (if you saved it like step 6).

  8. With this array, you can attach it to a scope variable in your controller, and then using an ng-repeat, display all the user images.

  9. Polish app.

  10. Release

  11. ????

  12. Profit!

Good luck. I love building apps so I'm happy to help if you get stuck, though something tells me you got this :wink:


Viewing all articles
Browse latest Browse all 228595

Trending Articles