Pārlūkot izejas kodu

download attachment and save as a new name

master
Patrick Peng Sun pirms 8 gadiem
vecāks
revīzija
a65814671a
2 mainītis faili ar 11 papildinājumiem un 3 dzēšanām
  1. +10
    -3
      crmAttachment.go
  2. +1
    -0
      crmAttachment_test.go

+ 10
- 3
crmAttachment.go Parādīt failu

@@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
)

type crmFileInfo struct {
@@ -131,16 +132,22 @@ func crmCreateAttachment(path string) (result attachmentInfo, err error) {
}

func crmDownloadAttachmentAs(fileID, saveAs string) (err error) {
return nil

f, err := crmDownloadAttachment(fileID)
if err != nil {
return
}
err = os.Rename(f, saveAs)
return
}

func crmDownloadAttachment(fileID string) (err error) {
func crmDownloadAttachment(fileID string) (filename string, err error) {
u := crmURL4DownloadAttachmet(fileID)
headers := map[string]string{}
headers["Authorization"] = crmAuthHeader()
f, _, err := saveURLwithHTTPHeader(u, headers)
log.Println(f)
return nil
return f, err
}

func crmURL4DownloadAttachmet(fileID string) string {

+ 1
- 0
crmAttachment_test.go Parādīt failu

@@ -25,4 +25,5 @@ func TestDecodeJsonResponse(t *testing.T) {
func TestCRMDownloadAttachment(t *testing.T) {
SetupConfig()
crmDownloadAttachment("591ef9c61d6ca779c")
crmDownloadAttachmentAs("591ef9c61d6ca779c", "/tmp/wechat_hitxy_测试")
}

Notiek ielāde…
Atcelt
Saglabāt