-
Notifications
You must be signed in to change notification settings - Fork 275
Uploading through curl
Janko Marohnić edited this page Nov 18, 2019
·
2 revisions
Exporting on the command line using the tool 'curl' helped me understand the format which shrine requires and could be useful if you want to script uploads of files to your rails backend.
Send picture
$ curl -X POST --form "file=@t-bird.jpg" http://localhost:9000/upload
{"id":"4b4d42e77b4fa7ecddbd93cd07845cc2.jpg","storage":"cache","metadata":{"filename":"t-bird.jpg","size":1478512,"mime_type":"image/jpeg"}}
NOTE: when we send the picture we use 'file' instead of 'image'
Send text form (optional)
$ curl -X POST -d "asset_item[name]=curl" http://localhost:9000/asset_items.json
Convert output to JSON
{id:"7276dc618cdd23bf3f5a9243d3c59399.jpg",storage:"cache",metadata:{filename:"t-bird.jpg",size:1478512,mime_type:"image/jpeg"}}.to_json
Result
"{\"id\":\"7276dc618cdd23bf3f5a9243d3c59399.jpg\",\"storage\":\"cache\",\"metadata\":{\"filename\":\"t-bird.jpg\",\"size\":1478512,\"mime_type\":\"image/jpeg\"}}"
POST text with the image data
$ curl -X POST -d "asset_item[name]=curl" -d 'asset_item[image]="{\"id\":\"7276dc618cdd23bf3f5a9243d3c59399.jpg\",\"storage\":\"cache\",\"metadata\":{\"filename\":\"t-bird.jpg\",\"size\":1478512,\"mime_type\":\"image/jpeg\"}}"' http://localhost:9000/asset_items.json