D
D
Doctor Bi2019-05-22 19:33:10
JavaScript
Doctor Bi, 2019-05-22 19:33:10

How to use ClipboardEvent or DataTransfer in safari?

Good afternoon!
I have a task to generate an image from canvas and "shove" it into And I do it this way:
<input type="file" />

function renderPreview(blob, input) {
        const fileData = new ClipboardEvent('').clipboardData ||
            new DataTransfer();
        const file = new File([blob], "img.png", { type: 'image/png' });
        fileData.items.add(file);
        input.files = fileData.files;
}

In chrome, everything works fine, the input has a file and I can work with it the way I need.
But in safari this is a problem.
As far as I understand, it does not know how to constructor ClipboardEvent, and Edge does not have a constructor File.
If possible, I need to write a file to the input, if there are suggestions, please tell me.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question