How to pass `partIndex` into `QuerySignHTTP` for `WriteMultipart`?

Migrated from How to pass partIndex to QuerySignHTTP for WriteMultipart?

Given code like this:

type HTTPSigner interface {
    QuerySignHTTP(op string, path string, expire time.Duration, pairs ...Pair) (req *http.Request, err error)
}

When using QuerySignHTTP for WriteMultipart in s3, seems there is no suitable way to pass in partIndex parameter as no global pair or system pair for it.

func (s *Storage) querySignHTTP(ctx context.Context, op string, path string, expire time.Duration, opt pairStorageQuerySignHTTP) (req *http.Request, err error) {
	rp := s.getAbsPath(path)

	switch op {
	case OpMultiparterWriteMultipart:
		writeMultiReq, _ := s.service.UploadPartRequest(&s3.UploadPartInput{
			Bucket:     aws.String(s.name),
			Key:        aws.String(rp),
			// FIXME: `PartNumber` and `UploadId` are needed.
			PartNumber: aws.Int64(1),
			UploadId:   aws.String("xxx"),
		})
		url, err := writeMultiReq.Presign(expire)
		if err != nil {
			return nil, err
		}
		req, err = http.NewRequest("PUT", url, nil)
	default:
		return nil, services.ErrCapabilityInsufficient
	}

	return req, err
}

Alternative Way

Add index system pair then use s3.WithIndex() to pass in partIndex for WriteMultipart .

Drawbacks

All similar operations need to add extra system pairs.

Proposal

Split HTTPSigner into multiple interfaces and add necessary parameters for different operations.

Here is the ongoing GSP (go-storage proposal) that focus on the issue:

1 Like