github.com/openimsdk/tools@v0.0.49/s3/s3.go (about) 1 // Copyright © 2023 OpenIM. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package s3 16 17 import ( 18 "context" 19 "net/http" 20 "net/url" 21 "time" 22 ) 23 24 type PartLimit struct { 25 MinPartSize int64 `json:"minPartSize"` 26 MaxPartSize int64 `json:"maxPartSize"` 27 MaxNumSize int64 `json:"maxNumSize"` 28 } 29 30 type InitiateMultipartUploadResult struct { 31 Bucket string `json:"bucket"` 32 Key string `json:"key"` 33 UploadID string `json:"uploadID"` 34 } 35 36 type MultipartUploadRequest struct { 37 UploadID string `json:"uploadId"` 38 Bucket string `json:"bucket"` 39 Key string `json:"key"` 40 Method string `json:"method"` 41 URL string `json:"url"` 42 Query url.Values `json:"query"` 43 Header http.Header `json:"header"` 44 PartKey string `json:"partKey"` 45 PartSize int64 `json:"partSize"` 46 FirstPart int `json:"firstPart"` 47 } 48 49 type Part struct { 50 PartNumber int `json:"partNumber"` 51 ETag string `json:"etag"` 52 } 53 54 type CompleteMultipartUploadResult struct { 55 Location string `json:"location"` 56 Bucket string `json:"bucket"` 57 Key string `json:"key"` 58 ETag string `json:"etag"` 59 } 60 61 type SignResult struct { 62 Parts []SignPart `json:"parts"` 63 } 64 65 type ObjectInfo struct { 66 ETag string `json:"etag"` 67 Key string `json:"name"` 68 Size int64 `json:"size"` 69 LastModified time.Time `json:"lastModified"` 70 } 71 72 type CopyObjectInfo struct { 73 Key string `json:"name"` 74 ETag string `json:"etag"` 75 } 76 77 type FormData struct { 78 URL string `json:"url"` 79 File string `json:"file"` 80 Header http.Header `json:"header"` 81 FormData map[string]string `json:"form"` 82 Expires time.Time `json:"expires"` 83 SuccessCodes []int `json:"successActionStatus"` 84 } 85 86 type SignPart struct { 87 PartNumber int `json:"partNumber"` 88 URL string `json:"url"` 89 Query url.Values `json:"query"` 90 Header http.Header `json:"header"` 91 } 92 93 type AuthSignResult struct { 94 URL string `json:"url"` 95 Query url.Values `json:"query"` 96 Header http.Header `json:"header"` 97 Parts []SignPart `json:"parts"` 98 } 99 100 type InitiateUpload struct { 101 UploadID string `json:"uploadId"` 102 Bucket string `json:"bucket"` 103 Key string `json:"key"` 104 Method string `json:"method"` 105 URL string `json:"url"` 106 Query url.Values `json:"query"` 107 Header http.Header `json:"header"` 108 PartKey string `json:"partKey"` 109 PartSize int64 `json:"partSize"` 110 FirstPart int `json:"firstPart"` 111 } 112 113 type UploadedPart struct { 114 PartNumber int `json:"partNumber"` 115 LastModified time.Time `json:"lastModified"` 116 ETag string `json:"etag"` 117 Size int64 `json:"size"` 118 } 119 120 type ListUploadedPartsResult struct { 121 Key string `xml:"Key"` 122 UploadID string `xml:"UploadId"` 123 NextPartNumberMarker int `xml:"NextPartNumberMarker"` 124 MaxParts int `xml:"MaxParts"` 125 UploadedParts []UploadedPart `xml:"Part"` 126 } 127 128 type Image struct { 129 Format string `json:"format"` 130 Width int `json:"width"` 131 Height int `json:"height"` 132 } 133 134 type AccessURLOption struct { 135 ContentType string `json:"contentType"` 136 Filename string `json:"filename"` 137 Image *Image `json:"image"` 138 } 139 140 type Interface interface { 141 Engine() string 142 PartLimit() *PartLimit 143 144 InitiateMultipartUpload(ctx context.Context, name string) (*InitiateMultipartUploadResult, error) 145 CompleteMultipartUpload(ctx context.Context, uploadID string, name string, parts []Part) (*CompleteMultipartUploadResult, error) 146 147 PartSize(ctx context.Context, size int64) (int64, error) 148 AuthSign(ctx context.Context, uploadID string, name string, expire time.Duration, partNumbers []int) (*AuthSignResult, error) 149 150 PresignedPutObject(ctx context.Context, name string, expire time.Duration) (string, error) 151 152 DeleteObject(ctx context.Context, name string) error 153 154 CopyObject(ctx context.Context, src string, dst string) (*CopyObjectInfo, error) 155 156 StatObject(ctx context.Context, name string) (*ObjectInfo, error) 157 158 IsNotFound(err error) bool 159 160 AbortMultipartUpload(ctx context.Context, uploadID string, name string) error 161 ListUploadedParts(ctx context.Context, uploadID string, name string, partNumberMarker int, maxParts int) (*ListUploadedPartsResult, error) 162 163 AccessURL(ctx context.Context, name string, expire time.Duration, opt *AccessURLOption) (string, error) 164 165 FormData(ctx context.Context, name string, size int64, contentType string, duration time.Duration) (*FormData, error) 166 }