|
@@ -1,11 +1,14 @@
|
|
package osm_sdk
|
|
package osm_sdk
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "bytes"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"git.sxidc.com/go-framework/baize/framework/core/api/response"
|
|
"git.sxidc.com/go-framework/baize/framework/core/api/response"
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
"git.sxidc.com/go-tools/utils/strutils"
|
|
"git.sxidc.com/service-supports/dapr_api/invoke"
|
|
"git.sxidc.com/service-supports/dapr_api/invoke"
|
|
"github.com/pkg/errors"
|
|
"github.com/pkg/errors"
|
|
|
|
+ "io"
|
|
|
|
+ "mime/multipart"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -503,6 +506,63 @@ func copyPublic(srcObjName, dstObjName string, requireInfos []string) error {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func CreateImage(reader io.Reader, objName string) (string, error) {
|
|
|
|
+ return createImage(reader, objName)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func CreateImageWithPrefix(reader io.Reader, objName string) (string, error) {
|
|
|
|
+ return createImage(reader, prefix+objName)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func createImage(reader io.Reader, objName string) (string, error) {
|
|
|
|
+ if strutils.IsStringEmpty(objName) {
|
|
|
|
+ return "", nil
|
|
|
|
+ }
|
|
|
|
+ bodyBuffer := &bytes.Buffer{}
|
|
|
|
+ multipartWriter := multipart.NewWriter(bodyBuffer)
|
|
|
|
+ // 添加字段
|
|
|
|
+ fieldWriter, err := multipartWriter.CreateFormField("objName")
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ _, err = fieldWriter.Write([]byte(objName))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 添加文件
|
|
|
|
+ fileWriter, err := multipartWriter.CreateFormFile("file", objName)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ _, err = io.Copy(fileWriter, reader)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ bodyByte, err := io.ReadAll(bodyBuffer)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+ responseBytes, err := invokeAPI.Post(servicePrefix+"/operation/obj/create/image", map[string]string{
|
|
|
|
+ "Content-Type": multipartWriter.FormDataContentType()}, bodyByte)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resp := new(response.InfoResponse[string])
|
|
|
|
+ err = json.Unmarshal(responseBytes, resp)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if !resp.Success {
|
|
|
|
+ return "", errors.New(resp.Msg)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resp.Info, nil
|
|
|
|
+}
|
|
|
|
+
|
|
//func Cp(f, t string) error {
|
|
//func Cp(f, t string) error {
|
|
// return CpOrigin(prefix+f, prefix+t)
|
|
// return CpOrigin(prefix+f, prefix+t)
|
|
//}
|
|
//}
|