Go Example
go
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
apiKey := "ocr_your_api_key"
apiUrl := "https://ocr.cargoffer.com"
// Upload
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
fw, _ := w.CreateFormFile("file", "invoice.pdf")
f, _ := os.Open("invoice.pdf")
io.Copy(fw, f)
f.Close()
w.Close()
req, _ := http.NewRequest("POST", apiUrl+"/api/upload", &buf)
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", w.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
var upload struct{ Job string }
json.NewDecoder(resp.Body).Decode(&upload)
// Analyze
resp, _ = http.Post(apiUrl+"/api/analyze/"+upload.Job,
"application/json", nil)
fmt.Println(resp.Status)
}