Useful blog

Uploading files using FormData objects through jQuery Ajax

The FormData object can simulate a complete form using a series of key value pairs, and then send the “form” using XML HttpRequest.

There are detailed instructions for using FormData objects on the Mozilla Developer website.

But in the file upload section, only the underlying XMLHttpRequest object sends the upload request, so how can we upload it through jQuery’s Ajax?

This article will introduce using the FormData object to upload files through jQuery.

Using th form to initialize the FormData object and upload files

Here are a few points to note:

After uploading, the server-side code needs to use the query parameter name file to obtain the file input stream object, becausedeclares name=”file”.

What if we don’t use theform to construct a FormData object?

Upload files by adding fields using the FormData object

Server side file reading

Starting from Servlet 3.0, uploaded files can be obtained through two interfaces: request. getPart() or request. getPars().

Exit mobile version