scripts.js

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);    });

Get Hands-On Artificial Intelligence on Amazon Web Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.