Search code examples
angularjsimagemongodbdeployd

How to save png image in mongodb with angularjs and deployd


I am working on an app where I need to retrieve images from URLS (for example http://foo.com/bar.png) and save them in mongodb. The app is built using angularjs and uses deployd for the API stuff. Here is the config.js file for the image collection:

{
    "type": "Collection",
    "properties": {
        "image": {
            "name": "image",
            "type": "image/png",
            "typeLabel": "image/png",
            "required": true,
            "id": "image",
            "order": 0
        }
    }
}

I have tried searching but I was unable to find anything for images and deployd. I just need a simple way to retrieve images from URLs, save them in mongodb and then render them later on.


Solution

  • There's no column type image/png AFAIK. We can use string instead of it. Why not inserting the image as data uri?

    {
        "type": "Collection",
        "properties": {
            "image": {
                "name": "image",
                "type": "string",
                "typeLabel": "string",
                "required": true,
                "id": "image",
                "order": 0
            }
        }
    }