0

I'm using the FormData to upload images using the following strategy using AJAX way:

https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects

So, if I upload an image, I can make an <input type="file" /> and then:

formData.append("userfile", fileInputElement.files[0]);

So, the content of fileInputElement.files[0] depends on the file I choose in the browser.

But I want to change the file. Maybe for the purpose of size compression, or trimming, or other transform.

I want to do these operation in the client side.

Maybe I may use canvas to do the transform, and finally got a base64 encoded image.

Is there any way to upload that image, as a natural way?

Maybe as the below form:

var getCustomFileContent = function(base64image) {
    // ... How
}

formData.append('img_field', getCustomFileContent(base64image));

Is this possible? How?

Alfred Huang
  • 17,654
  • 32
  • 118
  • 189

0 Answers0