Tencent/WeKnora · error

failed to upload file to S3: %w

Error message

failed to upload file to S3: %w

What it means

S3 PutObject failed while uploading the opened file (content type from header or extension fallback) to the generated prefixed object key, so the object was not stored; permissions, size limits, or connectivity failures are wrapped for the caller.

Source

Thrown at internal/application/service/file/s3.go:250

	}
	defer src.Close()

	// Determine content type
	contentType := file.Header.Get("Content-Type")
	if contentType == "" {
		contentType = utils.GetContentTypeByExt(ext)
	}

	// Upload file to S3
	_, err = s.client.PutObject(ctx, &s3.PutObjectInput{
		Bucket:        aws.String(s.bucketName),
		Key:           aws.String(objectName),
		Body:          src,
		ContentLength: aws.Int64(file.Size),
		ContentType:   aws.String(contentType),
	})
	if err != nil {
		return "", fmt.Errorf("failed to upload file to S3: %w", err)
	}

	return fmt.Sprintf("s3://%s/%s", s.bucketName, objectName), nil
}

// GetFile gets a file from S3
func (s *s3FileService) GetFile(ctx context.Context, filePath string) (io.ReadCloser, error) {
	objectName, err := s.parseS3FilePath(filePath)
	if err != nil {
		return nil, err
	}

	resp, err := s.client.GetObject(ctx, &s3.GetObjectInput{
		Bucket: aws.String(s.bucketName),
		Key:    aws.String(objectName),
	})
	if err != nil {
		return nil, fmt.Errorf("failed to get file from S3: %w", err)

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check S3 credentials and write permissions
  2. Verify bucket quota and object size limits
  3. Retry the upload; the key is fresh so retries are safe
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/application/service/file/s3.go:250 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/2ddbc4e25f948d57. Report an issue: GitHub.