(ctx context.Context, bucketName string, objectKey string, fileName string)
| 28 | } |
| 29 | |
| 30 | func (basics *Bucket) UploadFile(ctx context.Context, bucketName string, objectKey string, fileName string) (*int64, error) { |
| 31 | fileInfo, err := os.Stat(fileName) |
| 32 | if err != nil { |
| 33 | return nil, fmt.Errorf("Couldn't get file info for %v. Here's why: %v\n", fileName, err) |
| 34 | } |
| 35 | |
| 36 | file, err := os.Open(fileName) |
| 37 | if err != nil { |
| 38 | return nil, fmt.Errorf("Couldn't open file %v to upload. Here's why: %v\n", fileName, err) |
| 39 | } else { |
| 40 | defer file.Close() |
| 41 | |
| 42 | uploader := manager.NewUploader(basics.S3Client, func(u *manager.Uploader) { |
| 43 | u.PartSize = uploadPartSize |
| 44 | }) |
| 45 | |
| 46 | _, err := uploader.Upload(ctx, &s3.PutObjectInput{ |
| 47 | Bucket: aws.String(bucketName), |
| 48 | Key: aws.String(objectKey), |
| 49 | Body: file, |
| 50 | }) |
| 51 | |
| 52 | if err != nil { |
| 53 | var mu manager.MultiUploadFailure |
| 54 | if errors.As(err, &mu) { |
| 55 | return nil, fmt.Errorf("Error while uploading object to %s.\n"+ |
| 56 | "The UploadId is %s. Error is %v\n", bucketName, mu.UploadID(), err) |
| 57 | } else { |
| 58 | return nil, fmt.Errorf("Error while uploading object to %s.\n"+ |
| 59 | "Error is %v\n", bucketName, err) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fileSize := fileInfo.Size() |
| 64 | return &fileSize, nil |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | func (basics *Bucket) DownloadFile(ctx context.Context, bucketName string, objectKey string, fileName string) (*int64, error) { |
| 69 | f, err := os.Create(fileName) |
no test coverage detected