Browse Source

download attachment and save as a new name

master
Patrick Peng Sun 8 years ago
parent
commit
a65814671a
2 changed files with 11 additions and 3 deletions
  1. +10
    -3
      crmAttachment.go
  2. +1
    -0
      crmAttachment_test.go

+ 10
- 3
crmAttachment.go View File

"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
) )


type crmFileInfo struct { type crmFileInfo struct {
} }


func crmDownloadAttachmentAs(fileID, saveAs string) (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) u := crmURL4DownloadAttachmet(fileID)
headers := map[string]string{} headers := map[string]string{}
headers["Authorization"] = crmAuthHeader() headers["Authorization"] = crmAuthHeader()
f, _, err := saveURLwithHTTPHeader(u, headers) f, _, err := saveURLwithHTTPHeader(u, headers)
log.Println(f) log.Println(f)
return nil
return f, err
} }


func crmURL4DownloadAttachmet(fileID string) string { func crmURL4DownloadAttachmet(fileID string) string {

+ 1
- 0
crmAttachment_test.go View File

func TestCRMDownloadAttachment(t *testing.T) { func TestCRMDownloadAttachment(t *testing.T) {
SetupConfig() SetupConfig()
crmDownloadAttachment("591ef9c61d6ca779c") crmDownloadAttachment("591ef9c61d6ca779c")
crmDownloadAttachmentAs("591ef9c61d6ca779c", "/tmp/wechat_hitxy_测试")
} }

Loading…
Cancel
Save