html2canvas javascript screenshot and upload

maria

Would it be possible to use html2canvas (This) to take a picture of the user`s screen but also upload the image, get the upload link and send it with ajax to the webserver?

if so, how can i do this?

Oliver Barnwell

Yes it is certainly possible to do such a thing.

Firstly use the html2canvas api to take a picture of the user's screen:

html2canvas(document.body).then(function(canvas) {
});

Secondly use the following function to convert the returned canvas image into a base64 encoded URL (defaults to png):

canvas.toDataURL(); 

Specification For canvas.toDataURL

Now construct a request to send your base64 encoded url to an image uploading server (I'm using Imgur as an example).

html2canvas(document.body).then(function(canvas) {
    var dataURL = canvas.toDataURL();
    $.ajax({
        url: 'https://api.imgur.com/3/image',
        type: 'post',
        headers: {
            Authorization: 'yourauthcode'
        },
        data: {
            image: dataURL
        },
        dataType: 'json',
        success: function(response) {
            if(response.success) {
               // Post the imgur url to your server.
               $.post("yourlinkuploadserver", response.data.link);
            }
        }
    });
});

After the image has been uploaded you can POST the URL of the uploaded image to your web server.

Specification for $.post

Specification for $.ajax

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Take a screenshot of a external website in html2canvas javascript

From Dev

Take a screenshot of a external website in html2canvas javascript

From Dev

Textarea screenshot using Html2Canvas

From Dev

Html2canvas print screenshot

From Dev

angularjs unsafe:data; when capturing screenshot with html2canvas

From Dev

why google maps and charts are not supported by html2canvas in javascript?

From Dev

Javascript html2canvas cant get background

From Dev

Screenshot of canvas

From Dev

javascript - Default filename when saving from html2canvas or save as dialogue?

From Dev

upload and save screenshot taken from users webcam in django --canvas element to file

From Dev

Take a screenshot in mplayer2 and upload it to an image sharing site in one keypress

From Dev

Upload/Change image in Javascript/HTML

From Dev

How to upload an Android Wear screenshot to the play store?

From Dev

Slow screenshot upload for app1

From Dev

copy paste screenshot in summernote and upload as file

From Dev

Canvas ScreenShot not working

From Dev

javascript: upload image file and draw it into a canvas

From Dev

javascript: upload image file and draw it into a canvas

From Dev

TypeScript and Html2Canvas?

From Dev

html5 upload multiple files with javascript

From Dev

Upload JavaScript/HTML based app to Heroku

From Dev

Capture video screenshot using canvas

From Dev

make a client screenshot through canvas

From Dev

OSX: Automatically upload screenshot to imageBin and put URL in clipboard

From Dev

How to take a screenshot and then upload the image to imgur through terminal?

From Dev

How to take a screenshot and then upload the image to imgur through terminal?

From Dev

Javascript - Creating canvas image elements from file upload

From Dev

Programmatically trigger mac screenshot using Javascript

From Dev

How to take a screenshot of a web page by using Javascript

Related Related

  1. 1

    Take a screenshot of a external website in html2canvas javascript

  2. 2

    Take a screenshot of a external website in html2canvas javascript

  3. 3

    Textarea screenshot using Html2Canvas

  4. 4

    Html2canvas print screenshot

  5. 5

    angularjs unsafe:data; when capturing screenshot with html2canvas

  6. 6

    why google maps and charts are not supported by html2canvas in javascript?

  7. 7

    Javascript html2canvas cant get background

  8. 8

    Screenshot of canvas

  9. 9

    javascript - Default filename when saving from html2canvas or save as dialogue?

  10. 10

    upload and save screenshot taken from users webcam in django --canvas element to file

  11. 11

    Take a screenshot in mplayer2 and upload it to an image sharing site in one keypress

  12. 12

    Upload/Change image in Javascript/HTML

  13. 13

    How to upload an Android Wear screenshot to the play store?

  14. 14

    Slow screenshot upload for app1

  15. 15

    copy paste screenshot in summernote and upload as file

  16. 16

    Canvas ScreenShot not working

  17. 17

    javascript: upload image file and draw it into a canvas

  18. 18

    javascript: upload image file and draw it into a canvas

  19. 19

    TypeScript and Html2Canvas?

  20. 20

    html5 upload multiple files with javascript

  21. 21

    Upload JavaScript/HTML based app to Heroku

  22. 22

    Capture video screenshot using canvas

  23. 23

    make a client screenshot through canvas

  24. 24

    OSX: Automatically upload screenshot to imageBin and put URL in clipboard

  25. 25

    How to take a screenshot and then upload the image to imgur through terminal?

  26. 26

    How to take a screenshot and then upload the image to imgur through terminal?

  27. 27

    Javascript - Creating canvas image elements from file upload

  28. 28

    Programmatically trigger mac screenshot using Javascript

  29. 29

    How to take a screenshot of a web page by using Javascript

HotTag

Archive