Guest User

Untitled

a guest
Jan 18th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. html2canvas(document.querySelector("#" + imageHtmlId)).then(function(canvas) {
  2. var ranges = [...that.state.ranges];
  3.  
  4. // insert the thumbnail at the top of the page
  5.  
  6. document.body.appendChild(canvas);
  7. document.body.removeChild(imageHtml);
  8. ranges[0].pic = canvas.toDataURL("image/png", 0.1).replace("image/png", "image/octet-stream");
  9.  
  10. that.setState({
  11. ranges: ranges
  12. });
  13. return API.put("hands", `/hands/${that.props.match.params.handId}`, {
  14. body: that.state.ranges
  15. });
  16. })
  17.  
  18. createShareLink() {
  19. try {
  20. s3Upload(this.state.pic, this.state.id);
  21. } catch (e) {
  22. alert(e);
  23. this.setState({ isLoading: false });
  24. }
  25. }
  26.  
  27. import { Storage } from "aws-amplify";
  28.  
  29. export async function s3Upload(file, filename) {
  30. const stored = await Storage.put(filename, file, {
  31. contentType: file.type
  32. });
  33.  
  34. return stored.key;
  35. }
  36.  
  37. var link = document.getElementById('link');
  38. link.setAttribute('download', 'MintyPaper.png');
  39. link.setAttribute('href',
  40. canvas.toDataURL("image/png").replace("image/png", "image/octet-stream"));
  41. link.click();
Add Comment
Please, Sign In to add comment