|
@@ -9,6 +9,7 @@ import (
|
|
"io"
|
|
"io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
|
|
+ "net/http"
|
|
"sync"
|
|
"sync"
|
|
|
|
|
|
"app.yhyue.com/moapp/jybase/es"
|
|
"app.yhyue.com/moapp/jybase/es"
|
|
@@ -104,32 +105,35 @@ func UploadAttachment(bucketID, objectName string, data io.Reader, gzipEnabled b
|
|
}
|
|
}
|
|
|
|
|
|
// DownloadAttachment 下载附件,如果检测到数据为gzip压缩,则自动解压后返回
|
|
// DownloadAttachment 下载附件,如果检测到数据为gzip压缩,则自动解压后返回
|
|
-func DownloadAttachment(bucketID, objectName string) ([]byte, error) {
|
|
|
|
|
|
+func DownloadAttachment(bucketID, objectName string) ([]byte, http.Header, error) {
|
|
bucket, err := GetCachedBucket(bucketID)
|
|
bucket, err := GetCachedBucket(bucketID)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return nil, nil, err
|
|
}
|
|
}
|
|
|
|
|
|
- body, err := bucket.GetObject(objectName)
|
|
|
|
|
|
+ result, err := bucket.DoGetObject(&ossSDK.GetObjectRequest{objectName}, nil)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return nil, nil, err
|
|
}
|
|
}
|
|
- defer body.Close()
|
|
|
|
-
|
|
|
|
- data, err := ioutil.ReadAll(body)
|
|
|
|
|
|
+ defer result.Response.Body.Close()
|
|
|
|
+ data, err := ioutil.ReadAll(result.Response.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return nil, nil, err
|
|
}
|
|
}
|
|
// 判断是否为gzip压缩格式(判断前两个字节)
|
|
// 判断是否为gzip压缩格式(判断前两个字节)
|
|
if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b {
|
|
if len(data) >= 2 && data[0] == 0x1f && data[1] == 0x8b {
|
|
gzipReader, err := gzip.NewReader(bytes.NewReader(data))
|
|
gzipReader, err := gzip.NewReader(bytes.NewReader(data))
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, err
|
|
|
|
|
|
+ return nil, nil, err
|
|
}
|
|
}
|
|
defer gzipReader.Close()
|
|
defer gzipReader.Close()
|
|
- return ioutil.ReadAll(gzipReader)
|
|
|
|
|
|
+ data, err = ioutil.ReadAll(gzipReader)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return nil, nil, err
|
|
|
|
+ }
|
|
|
|
+ return data, result.Response.Headers, nil
|
|
}
|
|
}
|
|
- return data, nil
|
|
|
|
|
|
+ return data, result.Response.Headers, nil
|
|
}
|
|
}
|
|
|
|
|
|
// DeleteAttachment 删除附件
|
|
// DeleteAttachment 删除附件
|
|
@@ -155,7 +159,7 @@ func LoadOSSAccounts() {
|
|
|
|
|
|
// 获取标讯正文,优先从oss中取,再从es中取
|
|
// 获取标讯正文,优先从oss中取,再从es中取
|
|
func GetBidDetail(bucketID, objectName string) []byte {
|
|
func GetBidDetail(bucketID, objectName string) []byte {
|
|
- b, e := DownloadAttachment(bucketID, objectName)
|
|
|
|
|
|
+ b, _, e := DownloadAttachment(bucketID, objectName)
|
|
if e == nil && b != nil && len(b) > 0 {
|
|
if e == nil && b != nil && len(b) > 0 {
|
|
return b
|
|
return b
|
|
}
|
|
}
|