File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -109,10 +109,28 @@ func (h *Handler) WriteSQS(ctx context.Context, r io.Reader) error {
109109 key = strings .Trim (h .DestinationURI .Path , "/" ) + "/" + key
110110 }
111111
112+ // Convert to seekable reader to allow AWS SDK to retry S3 PutObject operations
113+ // by rewinding the stream. If the reader is already a bytes.Buffer, convert it
114+ // directly to bytes.Reader to avoid an extra copy.
115+ var body io.ReadSeeker
116+ if r != nil {
117+ // Check if r is a *bytes.Buffer to avoid unnecessary copy
118+ if buf , ok := r .(* bytes.Buffer ); ok {
119+ body = bytes .NewReader (buf .Bytes ())
120+ } else {
121+ // For other io.Reader types, read into memory
122+ data , err := io .ReadAll (r )
123+ if err != nil {
124+ return fmt .Errorf ("failed to read message data: %w" , err )
125+ }
126+ body = bytes .NewReader (data )
127+ }
128+ }
129+
112130 _ , err = h .S3Client .PutObject (ctx , & s3.PutObjectInput {
113131 Bucket : aws .String (h .DestinationURI .Host ),
114132 Key : & key ,
115- Body : r ,
133+ Body : body ,
116134 ContentType : aws .String ("application/x-aws-sqs" ),
117135 })
118136 if err != nil {
You can’t perform that action at this time.
0 commit comments