Reputation: 26061
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>
Upvotes: 2
Views: 4217
Reputation: 163272
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.
Upvotes: 4
Reputation: 114347
You will need to convert the image to Base64 encoding in order to stash it in JSON. JSON cannot contain binary data.
Upvotes: 2