-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfilemetadata.go
More file actions
76 lines (67 loc) · 2.73 KB
/
filemetadata.go
File metadata and controls
76 lines (67 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package imagekit
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"github.com/imagekit-developer/imagekit-go/v2/internal/apiquery"
"github.com/imagekit-developer/imagekit-go/v2/internal/requestconfig"
"github.com/imagekit-developer/imagekit-go/v2/option"
)
// FileMetadataService contains methods and other services that help with
// interacting with the ImageKit API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewFileMetadataService] method instead.
type FileMetadataService struct {
Options []option.RequestOption
}
// NewFileMetadataService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewFileMetadataService(opts ...option.RequestOption) (r FileMetadataService) {
r = FileMetadataService{}
r.Options = opts
return
}
// You can programmatically get image EXIF, pHash, and other metadata for uploaded
// files in the ImageKit.io media library using this API.
//
// You can also get the metadata in upload API response by passing `metadata` in
// `responseFields` parameter.
func (r *FileMetadataService) Get(ctx context.Context, fileID string, opts ...option.RequestOption) (res *Metadata, err error) {
opts = slices.Concat(r.Options, opts)
if fileID == "" {
err = errors.New("missing required fileId parameter")
return nil, err
}
path := fmt.Sprintf("v1/files/%s/metadata", fileID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// Get image EXIF, pHash, and other metadata from ImageKit.io powered remote URL
// using this API.
func (r *FileMetadataService) GetFromURL(ctx context.Context, query FileMetadataGetFromURLParams, opts ...option.RequestOption) (res *Metadata, err error) {
opts = slices.Concat(r.Options, opts)
path := "v1/metadata"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return res, err
}
type FileMetadataGetFromURLParams struct {
// Should be a valid file URL. It should be accessible using your ImageKit.io
// account.
URL string `query:"url" api:"required" format:"uri" json:"-"`
paramObj
}
// URLQuery serializes [FileMetadataGetFromURLParams]'s query parameters as
// `url.Values`.
func (r FileMetadataGetFromURLParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}