Improve model download

This commit is contained in:
Rodolphe Houdas 2021-09-01 01:19:43 +01:00
parent 6809a0a747
commit ecc52fe412
2 changed files with 26 additions and 14 deletions

View File

@ -16,7 +16,7 @@ app = Flask(__name__)
@app.route("/", methods=['POST'])
@cross_origin()
@cross_origin(expose_headers=["content-disposition"])
def upload_files():
project_id = str(uuid4())

View File

@ -114,6 +114,8 @@
inc++;
});
let filename = "";
const send_form = document.getElementById("files-form");
send_form.addEventListener("submit", (event) => {
const url = "https://cad.interstellai.re/upload";
@ -121,14 +123,19 @@
method: "POST",
body: new FormData(event.target)
})
.then( res => res.blob() )
.then( blob => {
addResult(blob);
.then(res => {
const header = res.headers.get('content-disposition');
const parts = header.split(';');
filename = parts[1].split('=')[1].replace(/['"]+/g, '');
return res.blob();
})
.then(blob => {
addResult(blob, filename);
});
event.preventDefault();
});
function addResult(blob) {
function addResult(blob, filename) {
const container = document.getElementById("result-viewer");
const title = document.createElement("h3");
@ -136,24 +143,29 @@
title.textContent = "Result";
const dl_icon = document.createElement("i");
dl_icon.classList.add("fa", "fa-download");
dl_icon.classList.add("fa", "fa-download", "mr2");
dl_icon.setAttribute("aria-hidden", "true");
const dl_button = document.createElement("button");
const dl_link = document.createElement("a");
const dl_button = document.createElement("div");
dl_button.appendChild(dl_icon);
dl_button.appendChild(document.createTextNode(" Download"));
dl_button.classList.add(..."f4 white bg-green ba b--dark-green mt2 ph4 pv3 center mw5 db shadow-2 grow".split(" "));
dl_button.addEventListener("click", (event) => {
const file = window.URL.createObjectURL(blob);
window.location.assign(file);
});
dl_button.appendChild(document.createTextNode("Download"));
dl_button.classList.add(..."f4 white bg-green ba b--dark-green mt2 flex items-center justify-center pv3 center db shadow-2 grow".split(" "));
dl_link.href = window.URL.createObjectURL(blob);
dl_link.download = filename;
dl_link.classList.add(..."center no-underline db mw5".split(" "));
dl_link.appendChild(dl_button);
const threejs_view = document.createElement("div");
threejs_view.classList.add(..."w-100 center h6".split(" "));
container.appendChild(title);
container.appendChild(threejs_view);
container.appendChild(dl_button);
container.appendChild(dl_link);
init(threejs_view, blob);
animate();