MCPcopy
hub / github.com/minio/minio-go / PutObjectFanOut

Method PutObjectFanOut

api-put-object-fan-out.go:72–167  ·  api-put-object-fan-out.go::Client.PutObjectFanOut

PutObjectFanOut - is a variant of PutObject instead of writing a single object from a single stream multiple objects are written, defined via a list of PutObjectFanOutRequests. Each entry in PutObjectFanOutRequest carries an object keyname and its relevant metadata if any. `Key` is mandatory, rest o

(ctx context.Context, bucket string, fanOutData io.Reader, fanOutReq PutObjectFanOutRequest)

Source from the content-addressed store, hash-verified

70// in PutObjectFanOutRequest carries an object keyname and its relevant metadata if any. `Key` is
71// mandatory, rest of the other options in PutObjectFanOutRequest are optional.
72func (c *Client) PutObjectFanOut(ctx context.Context, bucket string, fanOutData io.Reader, fanOutReq PutObjectFanOutRequest) ([]PutObjectFanOutResponse, error) {
73 if len(fanOutReq.Entries) == 0 {
74 return nil, errInvalidArgument("fan out requests cannot be empty")
75 }
76
77 policy := NewPostPolicy()
78 policy.SetBucket(bucket)
79 policy.SetKey(strconv.FormatInt(time.Now().UnixNano(), 16))
80
81 // Expires in 15 minutes.
82 policy.SetExpires(time.Now().UTC().Add(15 * time.Minute))
83
84 // Set encryption headers if any.
85 policy.SetEncryption(fanOutReq.SSE)
86
87 // Set checksum headers if any.
88 err := policy.SetChecksum(fanOutReq.Checksum)
89 if err != nil {
90 return nil, err
91 }
92
93 url, formData, err := c.PresignedPostPolicy(ctx, policy)
94 if err != nil {
95 return nil, err
96 }
97
98 r, w := io.Pipe()
99
100 req, err := http.NewRequest(http.MethodPost, url.String(), r)
101 if err != nil {
102 w.Close()
103 return nil, err
104 }
105
106 var b strings.Builder
107 enc := json.NewEncoder(&b)
108 for _, req := range fanOutReq.Entries {
109 if req.Key == "" {
110 w.Close()
111 return nil, errors.New("PutObjectFanOutRequest.Key is mandatory and cannot be empty")
112 }
113 if err = enc.Encode(&req); err != nil {
114 w.Close()
115 return nil, err
116 }
117 }
118
119 mwriter := multipart.NewWriter(w)
120 req.Header.Add("Content-Type", mwriter.FormDataContentType())
121
122 go func() {
123 defer w.Close()
124 defer mwriter.Close()
125
126 for k, v := range formData {
127 if err := mwriter.WriteField(k, v); err != nil {
128 return
129 }

Callers 1

mainFunction · 0.80

Calls 14

SetBucketMethod · 0.95
SetKeyMethod · 0.95
SetExpiresMethod · 0.95
SetEncryptionMethod · 0.95
SetChecksumMethod · 0.95
PresignedPostPolicyMethod · 0.95
doMethod · 0.95
errInvalidArgumentFunction · 0.85
NewPostPolicyFunction · 0.85
httpRespToErrorResponseFunction · 0.85
closeResponseFunction · 0.70
AddMethod · 0.45

Tested by

no test coverage detected