1
0
Fork 0
mirror of https://github.com/Luzifer/cam2mjpeg.git synced 2024-11-09 14:10:03 +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
import (
"encoding/base64"
"fmt"
"mime/multipart"
"net/http"
"net/textproto"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
@ -34,18 +36,26 @@ func handleMJPEG(res http.ResponseWriter, r *http.Request, imgs chan []byte, uid
return
case img := <-imgs:
err := func() error {
partHeader := make(textproto.MIMEHeader)
partHeader.Add("Content-Type", "image/jpeg")
partHeader.Add("Content-Transfer-Encoding", "base64")
partWriter, err := mimeWriter.CreatePart(partHeader)
if err != nil {
logger.WithError(err).Error("Unable to create mime part")
continue
return errors.Wrap(err, "Unable to create mime part")
}
_, 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 {
logger.WithError(err).Error("Unable to write image")
logger.WithError(err).Error("Unable to process image")
errC++
if errC > 5 {