Last active
October 30, 2022 22:11
-
-
Save michalkorzawski/9f15ecfa8d7432aadd3c9bbf95eda849 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/javascript/controllers/image_preview_controller.js | |
import ApplicationController from "./application_controller"; | |
export default class extends ApplicationController { | |
static targets = ["imagePreview"]; | |
... | |
renderImagePreview(file) { | |
const formData = new FormData(); | |
formData.append("image", file); | |
fetch("/convert_heic", { | |
method: "post", | |
body: formData | |
}).then(response => { | |
response.blob().then(imgBlob => { | |
let blobURL = URL.createObjectURL(imgBlob); | |
this.imagePreviewTarget.insertAdjacentHTML("beforeend", `<img src="${blobURL}">`); | |
}).catch(e => { | |
// logic to show alert flash msg | |
}) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment