Answer the question
In order to leave comments, you need to log in
Is it possible to change the contents of the uploaded image file using js and download it?
There is an image file image.png
Using any HEX editor, you can add random characters to the end of its content and get a new image file new-image.png , which in the image viewer will not differ from the first one.
Can this be done using JS? For example:
Load image file image.png with
Then read it with FileReader:<input type="file">
const fr = new FileReader();
fr.readAsText(file, "CP1251");
Answer the question
In order to leave comments, you need to log in
Can. Only not readAsText, but readAsArrayBuffer.
Conditionally like this:
toAppend
can also be a string - then it will be encoded as utf-8.
https://developer.mozilla.org/en-US/docs/Web/API/F...
https://developer.mozilla.org/en/docs/Web/API/Form...
const obj = {hello: 'world'};
const blob = new Blob([JSON.stringify(obj, null, 2)], {type : 'application/json'});
const file = new File([blob], "foo.txt", {
type: "text/plain",
});
const formData = new FormData();
formData.append("foo-file", file, "foo.txt");
const reqsponse = await fetch("https://developer.mozilla.org/", {
method: "POST",
body: formData,
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question