Be able to push marked up image back to the server.
This commit is contained in:
parent
35e5a00888
commit
4118866f7b
@ -50,6 +50,7 @@ type Upload struct {
|
||||
UploadedAt time.Time `json:"uploaded_at"`
|
||||
|
||||
OriginalFilename string `json:"original_file"` // path on the local disk
|
||||
MarkedUpFilename string `json:"markedup_file"` // a temporary file, if the user did some markup
|
||||
TemporaryFileToUpload string // post-watermark, or just original if unwatermarked
|
||||
|
||||
webhookURL string
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{ define "content" }}
|
||||
|
||||
<main role="main" class="" stylse="height:100%;" x-data="editor()" x-init="setup_canvas();">
|
||||
<main role="main" class="" x-data="editor()" x-init="setup_canvas();">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<canvas id="c" x-bind:style="canvas_style">
|
||||
@ -11,7 +11,7 @@
|
||||
<div id="tools-top" x-show="!toolbar">
|
||||
<button type="button" @click="add_some_text()" class="btn btn-primary">Add text</button>
|
||||
<button type="button" @click="crop()" class="btn btn-primary">Crop</button>
|
||||
<button type="button" @click="crop()" class="btn btn-primary">Apply</button>
|
||||
<button type="button" @click="apply()" class="btn btn-primary">Apply</button>
|
||||
</div>
|
||||
<div id="tools-delete" x-show="toolbar == 'text'">
|
||||
<button type="button" @click="delete_selected();" class="btn btn-primary" style="">delete</button>
|
||||
@ -137,6 +137,19 @@ function editor() {
|
||||
|
||||
});
|
||||
canvas.renderAll();
|
||||
},
|
||||
apply() {
|
||||
image_data = canvas.toDataURL('png');
|
||||
let formData = new FormData();
|
||||
formData.append('image', image_data);
|
||||
var url = new URL(window.location);
|
||||
var id = url.searchParams.get("id");
|
||||
fetch('/rest/upload/'+id+'/markup', {method: 'POST', body: formData})
|
||||
.then(response => response.json()) // convert to json
|
||||
.then(json => {
|
||||
console.log(json);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// selection:cleared
|
||||
|
@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@ -252,6 +253,23 @@ func (ws *WebService) modifyUpload(w http.ResponseWriter, r *http.Request) {
|
||||
resString, _ := json.Marshal(res)
|
||||
w.Write(resString)
|
||||
return
|
||||
} else if change == "markup" {
|
||||
newImageData := r.FormValue("image")
|
||||
//data:image/png;base64,xxxx
|
||||
// I know this is dumb, we should just send binary image data, but I can't
|
||||
// see that Fabric makes that possible.
|
||||
if strings.Index(newImageData, "data:image/png;base64,") != 0 {
|
||||
returnJSONError(w, "bad image data")
|
||||
return
|
||||
}
|
||||
imageDataBase64 := newImageData[22:]
|
||||
b, err := base64.StdEncoding.DecodeString(imageDataBase64)
|
||||
if err != nil {
|
||||
returnJSONError(w, err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("YAY %v", b)
|
||||
|
||||
} else {
|
||||
returnJSONError(w, "bad change type")
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user