|
- package main
-
- import (
- "encoding/json"
- "log"
- )
-
- type attachmentID struct {
- ID string `json:"attachmentId"`
- }
-
- func crmAttachFile(path string) (fileID string) {
- //http post
- r, _ := crmPostAttach(path)
- attach := attachmentID{}
- json.Unmarshal([]byte(r), &attach)
- return attach.ID
- }
-
- func crmPostAttachmentURL() string {
- return "https://c.hitxy.org.au/api/v1/Attachment/action/upload"
- }
-
- func crmAuthHeader() string {
- return "Basic cGF0cmljazpiNjFmYWRlMTM5OWYwY2ZjNmZjZjcxNTU0OTljNTNkOQ=="
- //return "Basic cGF0cmljazp3b3JraGFyZA=="
- }
-
- func crmFileDataString(path string) string {
- //read file
- //encode it
- return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXIAAAFyAQMAAADS6sNKAAAABlBMVEX///8AAABVwtN+AAABsklEQVR4nO2aS47EIAxEkXKAHClX7yPlAJHcwR8MgZnljCqqWrjzefQG29iQUiiKoiiK+h+J67Krcqg566s93n3I4/J2s1/1apP7shq9vU2PkMfk67TrO/UCN5s9M0ch/wq+uoI6hYjFO/k38Yaa0eHkX8GXYe6b0Wc9Qh6Sz3rssz/Msh4jD8X3I9t6raX2miKPxasr3F1UjfJTl+rN0HCFbfIf8kC8zn033NBTmyqx9oo8Ml97J98Faeu1ds7aVE31GHk43k1U3mHkfJRi5CF58V3MLrN7U+WJ4OEP5JF4i2grxYLPreq5MiOPxQdweWYvLZWrPxxT0JOH4rPKHraq16UbeTg+UrlEAWYOEPX2yn/IY/GezyVLbc/nl/8beVw+HucBRFULf0XI4/IZ1j73w8liWYg8Eh+ldoT1ERsgnWeQx+X7kZnA9xz03O8iD8X7tEeXXErpv9eyQeSBebsJIJtm94cpP5AH43cP8OinfKk2zeeP5GH56KfSFeZDCfKovNjOtcjYSv3oD+QxeP1prbL1U/m91llGkQfjXddQb9t54u/1G3kEnqIoiqKov9QXf1Q2La7tzOYAAAAASUVORK5CYII="
- }
-
- func crmPostAttach(path string) (resp string, err error) {
- headers := map[string]string{}
- headers["Authorization"] = crmAuthHeader()
- headers["Accept"] = "application/json, text/javascript, */*; q=0.01"
- data := []byte(crmFileDataString(path))
- URL := crmPostAttachmentURL()
- resp, err = postRAW(data, URL, headers)
- return
- }
-
- type attachmentInfo struct {
- ID string `json:"id"` //"id": "591e55398345683ee",
- Name string `json:"name"` //"name": "static_qr_code_without_logo.png",
- Deleted bool `json:"deleted"` //"deleted": false,
- Type string `json:"type"` // "type": "image\/png",
- Size int `json:"size"` //"size": 509,
- SourceID string `json:"sourceId"` //"sourceId": null,
- CreateAT string `json:"createAt"` //"createdAt": "2017-05-19 02:15:21",
- Role string `json:"role"` //"role": "Attachment",
- Storage string `json:"storage"` //"storage": null,
- StorageFielPath string `json:"storageFilePath"` //"storageFilePath": null,
- Global bool `json:"global"` // "global": false,
- ParentID string `json:"parentId"` // "parentId": null,
- ParentType string `json:"parentType"` // "parentType": null,
- RelatedID string `json:"relatedId"` // "relatedId": null,
- RelatedType string `json:"relatedType"` // "relatedType": null,
- CreatedByID string `json:"createdById"` // "createdById": "1",
- CreatedbyName string `json:"createdByName"` // "createdByName": "Admin"
- }
-
- func crmPatchAttachmentInfo(id string) (j string) {
- info := map[string]interface{}{}
- //{"name":"static_qr_code_without_logo.png","type":"image/png","role":"Attachment","size":509}
- info["name"] = "static_qr_code_without_logo.png"
- info["type"] = "image/png"
- info["role"] = "Attachment"
- info["size"] = 509
- url := "https://c.hitxy.org.au/api/v1/Attachment/591e5f7b9463d7147"
-
- headers := map[string]string{}
- headers["Authorization"] = crmAuthHeader()
- headers["Content-Type"] = "application/json"
-
- jb, _ := json.Marshal(info)
- log.Println(string(jb))
- j, _ = putRAW(jb, url, headers)
- return
- }
|