uploadPart - Uploads a part in a multipart upload.
(ctx context.Context, p uploadPartParams)
| 287 | |
| 288 | // uploadPart - Uploads a part in a multipart upload. |
| 289 | func (c *Client) uploadPart(ctx context.Context, p uploadPartParams) (ObjectPart, error) { |
| 290 | // Input validation. |
| 291 | if err := s3utils.CheckValidBucketName(p.bucketName); err != nil { |
| 292 | return ObjectPart{}, err |
| 293 | } |
| 294 | if err := s3utils.CheckValidObjectName(p.objectName); err != nil { |
| 295 | return ObjectPart{}, err |
| 296 | } |
| 297 | if p.size > maxPartSize { |
| 298 | return ObjectPart{}, errEntityTooLarge(p.size, maxPartSize, p.bucketName, p.objectName) |
| 299 | } |
| 300 | if p.size <= -1 { |
| 301 | return ObjectPart{}, errEntityTooSmall(p.size, p.bucketName, p.objectName) |
| 302 | } |
| 303 | if p.partNumber <= 0 { |
| 304 | return ObjectPart{}, errInvalidArgument("Part number cannot be negative or equal to zero.") |
| 305 | } |
| 306 | if p.uploadID == "" { |
| 307 | return ObjectPart{}, errInvalidArgument("UploadID cannot be empty.") |
| 308 | } |
| 309 | |
| 310 | // Get resources properly escaped and lined up before using them in http request. |
| 311 | urlValues := make(url.Values) |
| 312 | // Set part number. |
| 313 | urlValues.Set("partNumber", strconv.Itoa(p.partNumber)) |
| 314 | // Set upload id. |
| 315 | urlValues.Set("uploadId", p.uploadID) |
| 316 | |
| 317 | // Set encryption headers, if any. |
| 318 | if p.customHeader == nil { |
| 319 | p.customHeader = make(http.Header) |
| 320 | } |
| 321 | // https://docs.aws.amazon.com/AmazonS3/latest/API/mpUploadUploadPart.html |
| 322 | // Server-side encryption is supported by the S3 Multipart Upload actions. |
| 323 | // Unless you are using a customer-provided encryption key, you don't need |
| 324 | // to specify the encryption parameters in each UploadPart request. |
| 325 | if p.sse != nil && p.sse.Type() == encrypt.SSEC { |
| 326 | p.sse.Marshal(p.customHeader) |
| 327 | } |
| 328 | |
| 329 | reqMetadata := requestMetadata{ |
| 330 | bucketName: p.bucketName, |
| 331 | objectName: p.objectName, |
| 332 | queryValues: urlValues, |
| 333 | customHeader: p.customHeader, |
| 334 | contentBody: p.reader, |
| 335 | contentLength: p.size, |
| 336 | contentMD5Base64: p.md5Base64, |
| 337 | contentSHA256Hex: p.sha256Hex, |
| 338 | streamSha256: p.streamSha256, |
| 339 | trailer: p.trailer, |
| 340 | } |
| 341 | |
| 342 | // Execute PUT on each part. |
| 343 | resp, err := c.executeMethod(ctx, http.MethodPut, reqMetadata) |
| 344 | defer closeResponse(resp) |
| 345 | if err != nil { |
| 346 | return ObjectPart{}, err |