How to upload file without form using JavaScript ? Last Updated : 12 Jul, 2021 Comments Improve Suggest changes Like Article Like Report There are several approaches to upload a file without using the form in JavaScript: Approach 1: This approach is to use FormData that can upload a file without using any kind of form. The special thing about this is that network methods, such as fetch, can accept a FormData object as a body. It’s encoded and sent out with Content-Type — multipart/form-data. JavaScript Snippet: JavaScript var gfg = new FormData(); gfg.append('pictureFile', pictureInput.files[0]); // upload.php is the file to be uploaded $.ajax({ url: 'upload.php', type: 'POST', processData: false, contentType: false, dataType: 'json', data: gfg }); Approach 2: This approach is to use XMLHTTPRequest that can directly upload the file as the content inside the body of POST request. JavaScript Snippet: JavaScript // JavaScript Code var form = document.getElementById('the-form'); form.onsubmit = function () { var formData = new FormData(form); formData.append('file', file); var xhr = new XMLHttpRequest(); // Add any event handlers here... xhr.open('POST', form.getAttribute('action'), true); xhr.send(formData); // To avoid actual submission of the form return false; } Approach 3: This approach is to use simpleUpload plugin. HTML Code Snippet: HTML <!DOCTYPE html> <html> <body> <h2>Welcome To GFG</h2> <input type="file" name="arquivo" id="simpleUpload" multiple> <button type="button" id="upload"> Upload </button> </body> </html> JavaScript Snippet: JavaScript $('#simpleUpload').simpleUpload({ // upload.php is the file // to be uploaded url: 'upload.php', trigger: '#upload', success: function (data) { alert('Successfully Uploaded'); } }); Output: Comment More infoAdvertise with us Next Article How to upload file without form using JavaScript ? S sankalpsharma424 Follow Improve Article Tags : JavaScript Web Technologies HTML HTML-Misc JavaScript-Misc +1 More Similar Reads How to Upload Files in JavaScript? We upload files using JavaScript, for this we have to capture form elements, gather information from FormData for easier file uploads, intercept submission events, and utilize Fetch API for asynchronous server requests, for enhanced user experience and efficient data handling. ApproachProject Setup: 1 min read How to upload files using HTML to website ? Every file that needs to be uploaded to the website, required the basic form which facilitates uploading. This feature is essential when we are filling out the form on a specific website. This file upload may support a variety of file formats along with various types of files. The file uploading fea 2 min read File Type Validation while Uploading it using JavaScript File type validation is essential for web applications that allow users to upload files. By checking the file extension on the client side using JavaScript, you can provide a smooth and efficient user experience by quickly notifying users if their file isn't supported. This method is often preferred 3 min read How to Upload File with Progress Bar using Node.js ? Uploading files in NodeJS involves transferring files from the client's location to the server's location. A progress bar is a visual component that displays the percentage of the total file upload. In this tutorial, we will create a local server and demonstrate how to upload files to a destination 4 min read How to read a local text file using JavaScript? JavaScript can read local files using the File API, which is supported by most modern browsers. The File API allows JavaScript to read the contents of files chosen by the user, typically through an HTML file input element.The File object represents a file (like a text file or image) selected by the 6 min read Like