"Main `HavenOnDemand` function, used to call **Haven OnDemand** API."function call_HOD( endpoint :: String, async :: Bool, # Some endpoints are `async_only`. files :: Vector{FileParam}, options :: Dict; api_url :: String = "https://api.havenondemand.com", version :: Int = 1, default_version :: Int = 1, )
try options["apikey"] = _HOD_API_KEY catch error("Use `HavenOnDemand.set_api_key(api_key::AbstractString)` first.") end
sync_str = async ? "async" : "sync" r = post( "$(api_url)/$(version)/api/$(sync_str)/$(endpoint)/v$(default_version)", files = files, # <--- HERE'S THE PROBLEM! data = options ) return r.status == 200 ? json(r) : throw(HODException(r))end
"`DataFrame` that holds the `HavenOnDemand` data used wrap the API."const _HOD_API = readtable( joinpath(Pkg.dir("HavenOnDemand"), "src", "api.data"), separator = ' ')
# Meta wrap most of the API:for row in eachrow(_HOD_API::DataFrame) func_name, endpoint, async_only, description = [v for (k, v) in row] title = join([ucfirst(s) for s in split(func_name, '_')], ' ') docstring = """ **HPE Haven OnDemand: $(title)**
`$(func_name)([kwargs...])`
$description
All the arguments are optional and they must be supplied as keyword arguments, non valid keyword names are ignored.
For information about valid arguments, visit:
"""
@eval begin @doc $docstring -> function $(symbol(func_name))(; file = [], kwargs...) return call_HOD( $endpoint, $async_only, [FileParam(open(f)) for f in file], Dict(kwargs) ) end endendERROR: Multiple body options specified. Please only specify one in do_stream_request at C:\Users\Peter\.julia\v0.4\Requests\src\Requests.jl:268julia> post("$(api_url)/$(version)/api/$(sync_str)/$(endpoint)/v$(default_version)", files = [FileParam("open(text.txt"))], data = Dict("apikey" => ENV["HOD_API_KEY"]))
ERROR: Multiple body options specified. Please only specify one in do_stream_request at C:\Users\Peter\.julia\v0.4\Requests\src\Requests.jl:268curl -X POST --form "apikey=<API_KEY>" --form "file=@myscan.pdf" --form "mode=document_photo" https://api.idolondemand.com/1/api/async/ocrdocument/v1
<html>
<head>
<title>Multipart Form Example</title>
</head>
<body>
<form action="https://api.idolondemand.com/1/api/sync/ocrdocument/v1"
method="post" enctype="multipart/form-data">
<p><input type="hidden" name="apikey" value="your-apikey-here"></p>
<p><input type="file" name="file"></p>
<p><button type="submit">Submit</button></p>
</form>
</body>
</html>
var needle = require('needle');
var data = {
apikey: myapikey,
file: { file: 'myscan.pdf', content_type: 'multipart/form-data' }
}
needle.post('https://api.idolondemand.com/1/api/async/ocrdocument/v1', data, { multipart: true }, function(err, resp, body) {
console.log(body)
// needle will read the file and include it in the form-data as binary
});
require 'httpclient'
require 'json'
data={file:open("myscan.pdf"), mode:"document_photo", apikey:"apikey"}
clnt = HTTPClient.new
resp=clnt.post(url, data)
body=JSON.parse(resp.body)
files = {'file': open('myscan.pdf', 'rb')}
data= {'apikey':myapikey,'mode':'document_photo'}
requests.post("https://api.idolondemand.com/1/api/async/ocrdocument/v1",data=data,files=files)
print r.json()
Pkg.add("Requests")
using Requests
import Requests: get, post, put, delete, options
filenamne = "/path/to/file"
response = post("http://api.havenondemand.com/1/api/sync/ocrdocument/v1"; data=Dict("apikey"=>"YOUR_APIKEY", "file"=>FileParam(open(filename,"r"),"text/julia","file2","file2.jl",true)))
readall(response)