October 2019
Intermediate to advanced
426 pages
10h 8m
English
The first part of the Contact Organizer's scripts.js file is the same implementation of image upload from the Pictorial Translator project:
"use strict";const serverUrl = "http://127.0.0.1:8000";class HttpError extends Error { constructor(response) { super(`${response.status} for ${response.url}`); this.name = "HttpError"; this.response = response; }}async function uploadImage() { // encode input file as base64 string for upload let file = document.getElementById("file").files[0]; let converter = new Promise(function(resolve, reject) { const reader = new FileReader(); reader.readAsDataURL(file); reader.onload = () => resolve(reader.result .toString().replace(/^data:(.*,)?/, '')); reader.onerror = (error) => reject(error); });
Read now
Unlock full access