github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/httpx/httpx_attachment.go (about)

     1  package httpx
     2  
     3  import (
     4  	"bytes"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/kit/kit"
     7  )
     8  
     9  func NewAttachment(filename string, contentType string) *Attachment {
    10  	return &Attachment{
    11  		filename:    filename,
    12  		contentType: contentType,
    13  	}
    14  }
    15  
    16  type Attachment struct {
    17  	filename    string
    18  	contentType string
    19  	bytes.Buffer
    20  }
    21  
    22  func (a *Attachment) ContentType() string {
    23  	if a.contentType == "" {
    24  		return MIME_OCTET_STREAM
    25  	}
    26  	return a.contentType
    27  }
    28  
    29  func (a *Attachment) Meta() kit.Metadata {
    30  	metadata := kit.Metadata{}
    31  	metadata.Add(HeaderContentDisposition, "attachment; filename="+a.filename)
    32  	return metadata
    33  }