You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
780 B
40 lines
780 B
package image
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// UploadImageFileResponse struct to enable image
|
|
type UploadImageFileResponse struct {
|
|
// ImageFileUri
|
|
ImageFileUri string `json:"image_file_uri"`
|
|
}
|
|
|
|
// UploadImageFile uploads file image to platform
|
|
func (i Image) UploadImageFile(ctx context.Context, filePath string) (string, error) {
|
|
file, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return "", fmt.Errorf("can not read file %v", err)
|
|
}
|
|
|
|
url := "/cloudbroker/image/uploadImageFile"
|
|
|
|
res, err := i.client.DecortApiCall(ctx, http.MethodPost, url, file)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
result := UploadImageFileResponse{}
|
|
|
|
err = json.Unmarshal(res, &result)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return result.ImageFileUri, nil
|
|
}
|