{"_id":"550ada9e921b7d0d00228880","user":"550a378e635c660d00527fd7","version":{"_id":"550ada9d921b7d0d00228876","forked_from":"550a3b2542fff40d00ae5ffb","project":"550a379f635c660d00527fd8","__v":3,"createdAt":"2015-03-19T14:18:05.245Z","releaseDate":"2015-03-19T14:18:05.245Z","categories":["550ada9d921b7d0d00228877","550ada9d921b7d0d00228878","550ada9d921b7d0d00228879","550ada9d921b7d0d0022887a","550ada9d921b7d0d0022887b","550ada9d921b7d0d0022887c","550ada9d921b7d0d0022887d","5523e61e71c0542100993493","55246f72ccc28a0d0062c560"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0.0"},"__v":8,"project":"550a379f635c660d00527fd8","category":{"_id":"550ada9d921b7d0d0022887a","__v":2,"project":"550a379f635c660d00527fd8","version":"550ada9d921b7d0d00228876","pages":["550ada9e921b7d0d0022887f","550ada9e921b7d0d00228880","550ada9e921b7d0d00228881","5526826eb87cef230047be0e"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-19T02:55:05.573Z","from_sync":false,"order":4,"slug":"helpers-extras","title":"Helpers & Extras"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-03-19T02:55:30.830Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"Some endpoints take a file (subreddit images for example). The helper `Snoocore.file` can be used to properly format a file to send in an endpoint argument.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Snoocore.file(filename, mimeType, fileData)\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n# Node.js\n\nRead in the file contents (in this case an image):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var fs = require('fs');\\nvar iconData = fs.readFileSync('appicon.png');\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nThen pass the image data into `Snoocore.file` with the appropriate values:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"return reddit('/r/$subreddit/api/upload_sr_img').post({\\n  $subreddit: 'some subreddit',\\n  file: Snoocore.file('appicon.png', 'image/png', iconData),\\n  header: 1,\\n  img_type: 'png',\\n  name: 'test-foo-bar'\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n# Browser\n\nCheck out the example:\n\nhttps://github.com/trevorsenior/snoocore-examples/blob/master/oauth-implicit.html","excerpt":"","slug":"file-upload","type":"basic","title":"File Upload"}
Some endpoints take a file (subreddit images for example). The helper `Snoocore.file` can be used to properly format a file to send in an endpoint argument. [block:code] { "codes": [ { "code": "Snoocore.file(filename, mimeType, fileData)", "language": "javascript" } ] } [/block] # Node.js Read in the file contents (in this case an image): [block:code] { "codes": [ { "code": "var fs = require('fs');\nvar iconData = fs.readFileSync('appicon.png');", "language": "javascript" } ] } [/block] Then pass the image data into `Snoocore.file` with the appropriate values: [block:code] { "codes": [ { "code": "return reddit('/r/$subreddit/api/upload_sr_img').post({\n $subreddit: 'some subreddit',\n file: Snoocore.file('appicon.png', 'image/png', iconData),\n header: 1,\n img_type: 'png',\n name: 'test-foo-bar'\n});", "language": "javascript" } ] } [/block] # Browser Check out the example: https://github.com/trevorsenior/snoocore-examples/blob/master/oauth-implicit.html