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:
parent
1a24784bd0
commit
7dd31bad1c
1 changed files with 19 additions and 9 deletions
18
mjpeg.go
18
mjpeg.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue