capture image on initial save

similar to #111
This commit is contained in:
Kurt Hutten
2021-02-27 13:24:48 +11:00
parent 3cae431e61
commit 794ff480fd
4 changed files with 117 additions and 66 deletions

View File

@@ -1,5 +1,7 @@
// TODO: create a tidy util for uploading to Cloudinary and returning the public ID
import axios from 'axios'
import { threejsViewport } from 'src/cascade/js/MainPage/CascadeState'
import CascadeController from 'src/helpers/cascadeController'
const CLOUDINARY_UPLOAD_PRESET = 'CadHub_project_images'
const CLOUDINARY_UPLOAD_URL = 'https://api.cloudinary.com/v1_1/irevdev/upload'
@@ -18,4 +20,13 @@ export async function uploadToCloudinary(imgBlob) {
} catch (e) {
console.error('ERROR', e)
}
}
}
export const captureAndSaveViewport = async () => {
// Get the canvas image as a Data URL
const imgBlob = await CascadeController.capture(threejsViewport.environment)
// Upload the image to Cloudinary
const { public_id: publicId } = await uploadToCloudinary(imgBlob)
return { publicId, imgBlob }
}