2

I trying to create a extension for a browser and i want do save images local. I was hoping to save the images in a json file. I'm pretty lost has how to do its. Below is my code although I'm sure that I am pretty far off. Thanks

<label>Add New Image From Desktop</label>
        <input type="radio" title="Add New Image From Local Machine" name="addMethod" id="radio" />
        </br>
        <input  type="file" id="file-field"/>
        <input type="button" id="upload" value="Submit" />
        </br>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <script type="text/javascript" language="JavaScript">
            $(document).ready(function() {
                $("#upload").click(function(data) {
                    //alert(data);
                    $.ajax({
                        type : "POST",
                        url : "settings.json",
                        dataType : 'json',
                        data : {
                            json : JSONArray.stringify(data) /* convert here only */
                        }
                    });
                    window.location.reload();
                });
            });
        </script>
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
  • 1
    You may want to check out [Get image data in Javascript?][1]. [1]: http://stackoverflow.com/questions/934012/get-image-data-in-javascript – Fostah May 03 '12 at 20:40

2 Answers2

4

JSON has no real storage for binary data. If you believe you really must do this, the best you can do is base64-encode your data.

Brad
  • 159,648
  • 54
  • 349
  • 530
2

You will need to convert the image to Base64 encoding in order to stash it in JSON. JSON cannot contain binary data.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176