1
0
Fork 0
mirror of https://github.com/Luzifer/cam2mjpeg.git synced 2024-12-21 01:41:18 +00:00

Add base64 encoding of image

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2019-04-29 11:34:13 +02:00
parent 1a24784bd0
commit 7dd31bad1c
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E

View file

@ -1,11 +1,13 @@
package main package main
import ( import (
"encoding/base64"
"fmt" "fmt"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"net/textproto" "net/textproto"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@ -34,18 +36,26 @@ func handleMJPEG(res http.ResponseWriter, r *http.Request, imgs chan []byte, uid
return return
case img := <-imgs: case img := <-imgs:
err := func() error {
partHeader := make(textproto.MIMEHeader) partHeader := make(textproto.MIMEHeader)
partHeader.Add("Content-Type", "image/jpeg") partHeader.Add("Content-Type", "image/jpeg")
partHeader.Add("Content-Transfer-Encoding", "base64")
partWriter, err := mimeWriter.CreatePart(partHeader) partWriter, err := mimeWriter.CreatePart(partHeader)
if err != nil { if err != nil {
logger.WithError(err).Error("Unable to create mime part") return errors.Wrap(err, "Unable to create mime part")
continue
} }
_, err = partWriter.Write(img) b64w := base64.NewEncoder(base64.StdEncoding, partWriter)
defer b64w.Close()
_, err = b64w.Write(img)
return errors.Wrap(err, "Unable to write image")
}()
if err != nil { if err != nil {
logger.WithError(err).Error("Unable to write image") logger.WithError(err).Error("Unable to process image")
errC++ errC++
if errC > 5 { if errC > 5 {