W
W
WStanley2020-01-11 11:08:03
JavaScript
WStanley, 2020-01-11 11:08:03

Vue cropperjs how to send a jpeg image?

Good day everyone!
I wrote a component that uses the cropperjs
library. Files in png format are sent to the server and I can’t make jpeg files go.
Apparently there is not enough knowledge in js
Tell me how to convert the file to jpeg before sending?
send function:

cropImage() {
    this.cropper.getCroppedCanvas({
        width: 800,
        height: 800,
        minWidth: 256,
        minHeight: 256,
        maxWidth: 800,
        maxHeight: 800,
    })
    .toBlob((blob) => {
        let formData = new FormData();  
        formData.append('image', blob, 'image.png');
        if (this.name) formData.append('name', this.name);
        axios({
            method: 'POST',
            url: '/user_load_post/',
            xsrfHeaderName: 'X-CSRFToken',
            headers: {
                'Content-Type': 'multipart/form-data',
                'X-CSRFToken': this.$getCookie('csrftoken')
            },
            data: formData
        })
        .then(response => console.log(response))
        .catch(error => console.log(error))
    })
},

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2020-01-11
@WStanley

Just above
https://developer.mozilla.org/en-US/docs/Web/API/H...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question