{"id":21483,"date":"2022-06-30T16:21:00","date_gmt":"2022-06-30T23:21:00","guid":{"rendered":"http:\/\/file_upload_with_ajax"},"modified":"2026-11-04T12:48:40","modified_gmt":"2026-11-04T20:48:40","slug":"file_upload_with_ajax","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","title":{"rendered":"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p><strong>Key takeaways<\/strong><\/p>\n<ul>\n<li>An AJAX file upload posts the file in a background HTTP request, so the page the user is looking at never reloads.<\/li>\n<li>Three pieces do the work: a FormData object holding the file, XMLHttpRequest or fetch to send it, and a server endpoint that reads the multipart request.<\/li>\n<li>Upload progress events fire on xhr.upload, and the listeners have to be attached before open() is called. fetch has no upload progress event at all.<\/li>\n<li>Never trust the filename, the extension or the type field the browser sends. Verify the type from the bytes on the server, and store the file under a name you generate.<\/li>\n<li>Posting straight from the browser to Cloudinary removes the storage, validation and delivery work from your own server, and the file never passes through it.<\/li>\n<\/ul>\n<p>AJAX <a href=\"https:\/\/cloudinary.com\/blog\/automating_file_upload_and_sharing\">file upload<\/a> is the process of uploading files from a local computer to a server. When a user selects a file in the browser and clicks the submit button, the browser copies the file from the local machine and sends it to the server. The server then saves the file to the specified location.<\/p>\n<p>In this article, you\u2019ll find:<\/p>\n<ul>\n<li>How to perform a PHP AJAX file upload<\/li>\n<li>A useful JavaScript AJAX file upload example<\/li>\n<li>An AJAX file upload example using Cloudinary for free<\/li>\n<li>How to add an upload progress bar, a cancel button and multiple-file support<\/li>\n<li>How XMLHttpRequest, fetch and jQuery $.ajax compare for uploads<\/li>\n<li>How Cloudinary compares with Uppy, Dropzone.js, Filestack and Uploadcare<\/li>\n<\/ul>\n<p>The HTML form tag has an action attribute pointing to the script that will take care of the actual upload process. The form tag also has a method attribute that specifies the kind of operation this form will undertake, which is POST. AJAX uses the browser\u2019s built-in XMLHttpRequest object to request data from the web server. It also uses JS and HTML DOM to use and display the data.<\/p>\n<p>Web apps built using AJAX are efficient because they can quickly send and fetch data from the server without affecting the display of the existing page. Files can be uploaded to a backend server or directly to the cloud using a solution like <a href=\"https:\/\/cloudinary.com\/platform\">Cloudinary<\/a>.<\/p>\n<p>There are the general steps for uploading a file using AJAX:<\/p>\n<ul>\n<li>Set up an instance for XMLHttpRequest.<\/li>\n<li>Set up objects for various XMLHttpRequest handlers.<\/li>\n<li>Set an AJAX request to send data to the back end.<\/li>\n<li>Validate the form.<\/li>\n<li>Provide feedback to the user.<\/li>\n<\/ul>\n<p>To make this process easier, you can use Cloudinary, a cloud-based, end-to-end media-management solution that can easily create, manage and deliver their digital experiences across any browser, device and bandwidth. Make sure you try this yourself, claim your <a href=\"https:\/\/cloudinary.com\/users\/register\/free\">free Cloudinary account<\/a> now.<\/p>\n<p>This article describes how easy it is to do an AJAX file upload with Cloudinary using only a few lines of code and no need for any of the above tasks.<\/p>\n<h2>What Is an AJAX File Upload?<\/h2>\n<p>An AJAX (Asynchronous JavaScript and XML) file upload is a file transfer made with a background HTTP request instead of a form submission. A plain form with a file input navigates the browser to the server\u2019s response, which throws away the page the user was on. An AJAX upload intercepts the submit event, builds the request in JavaScript and sends it, so the user keeps their scroll position, their other form fields and any state the app holds in memory.<\/p>\n<p>Three pieces do the work:<\/p>\n<ul>\n<li>\n<strong>FormData<\/strong> builds a multipart\/form-data request body from the File object, and sets the Content-Type header with the correct boundary string.<\/li>\n<li>\n<strong>XMLHttpRequest<\/strong> or <strong>fetch<\/strong> sends that body to a URL you choose, asynchronously.<\/li>\n<li>\n<strong>Your server<\/strong> receives the request exactly as it would receive a native form post, reads the file, validates it and stores it.<\/li>\n<\/ul>\n<p>Nothing about the file itself changes. What changes is who controls the page after the bytes leave: with an AJAX upload, your JavaScript does.<\/p>\n<h2>How Do You Upload a File With AJAX?<\/h2>\n<p>The markup needs a file input, a submit button and somewhere to report status. It does not need an action attribute, because the submit event is intercepted before the browser would use it.<\/p>\n<pre class=\"js-syntax-highlighted\"><code>&lt;form id=&quot;upload-form&quot;&gt;\n  &lt;label for=&quot;file&quot;&gt;Choose a file&lt;\/label&gt;\n  &lt;input type=&quot;file&quot; id=&quot;file&quot; name=&quot;file&quot; accept=&quot;image\/png,image\/jpeg,image\/webp&quot; required&gt;\n  &lt;button type=&quot;submit&quot;&gt;Upload&lt;\/button&gt;\n&lt;\/form&gt;\n\n&lt;p id=&quot;status&quot; role=&quot;status&quot; aria-live=&quot;polite&quot;&gt;&lt;\/p&gt;\n\n&lt;script src=&quot;upload.js&quot;&gt;&lt;\/script&gt;\n Code language: HTML, XML ( xml )\nupload.js holds the whole client side:\nconst form = document.querySelector('#upload-form');\nconst input = document.querySelector('#file');\nconst statusEl = document.querySelector('#status');\n\nform.addEventListener('submit', (event) =&gt; {\n  event.preventDefault();\n\n  const file = input.files[0];\n  if (!file) {\n    statusEl.textContent = 'Choose a file first.';\n    return;\n  }\n\n  const body = new FormData();\n  body.append('file', file, file.name);\n\n  const xhr = new XMLHttpRequest();\n\n  xhr.addEventListener('load', () =&gt; {\n    statusEl.textContent = xhr.status === 200\n      ? 'Upload complete.'\n      : 'The server rejected the upload (HTTP ' + xhr.status + ').';\n  });\n\n  xhr.addEventListener('error', () =&gt; {\n    statusEl.textContent = 'Network error. Check the connection and try again.';\n  });\n\n  xhr.open('POST', '\/fileUpload.php');\n  xhr.send(body);\n\n  statusEl.textContent = 'Uploading...';\n});\n\n<\/code><\/pre>\n<p>That is a working AJAX file upload, with no library and no account. Point it at any endpoint that reads a multipart\/form-data field named file.<\/p>\n<p>Two things in it are easy to get wrong:<\/p>\n<ol>\n<li>load fires when the response arrives, including on a 4xx or 5xx, so check xhr.status yourself rather than treating load as success.<\/li>\n<li>Don\u2019t set Content-Type by hand. Setting it overwrites the multipart boundary that FormData generated, and the server then parses an empty request.<\/li>\n<\/ol>\n<h2><strong>Preliminary Steps: Create a Cloudinary Account and an Upload Preset<\/strong><\/h2>\n<p>As a first step, create a <a href=\"https:\/\/cloudinary.com\/users\/register\/free\">free Cloudinary account<\/a>, which includes a dashboard, a unique cloud name for you, an API key, and an API secret, which you\u2019ll need to work with Cloudinary.<\/p>\n<p>Subsequently, create an <a href=\"https:\/\/cloudinary.com\/documentation\/upload_presets\">upload preset<\/a>, which defines the options that apply to all your uploads.<\/p>\n<p>For a browser upload, set the preset\u2019s signing mode to unsigned. Cloudinary\u2019s <a href=\"https:\/\/cloudinary.com\/documentation\/upload_images\">upload documentation<\/a> states that unsigned uploads require an unsigned upload preset, and that for security reasons only a small set of upload parameters can be passed directly in an unsigned upload call, so everything else has to be configured on the preset.<\/p>\n<p>That means the preset where the restrictions live: set <code>allowed_formats<\/code> and a maximum file size there, and keep the format list narrow. Treat the preset name as sensitive, because an unsigned preset accepts uploads from anyone who knows it.<\/p>\n<h2>Direct Ajax File Uploads With Cloudinary<\/h2>\n<p>Follow these simple steps:<\/p>\n<p><strong>Create an HTML form.<\/strong><\/p>\n<p>In your root directory, create an HTML form (an index.html file) with the following code, which contains the fields for file uploads:<\/p>\n<p><strong>index.html<\/strong><\/p>\n<pre class=\"js-syntax-highlighted\"><code> &lt;!DOCTYPE html &gt; \n &lt; html lang = &quot;en&quot; &gt; \n &lt; head &gt; \n &lt; meta charset = &quot;UTF-8&quot; &gt; \n &lt; title &gt; AJAX File Uploads With Cloudinary &lt;\/ title &gt; \n &lt;\/ head &gt; \n &lt; body &gt; \n &lt; form id = &quot;file-form&quot; action = &quot;fileUpload.php&quot; method = &quot;post&quot; enctype = &quot;multipart\/form-data&quot; &gt; \n Upload a File:\n &lt; input type = &quot;file&quot; id = &quot;myfile&quot; name = &quot;myfile&quot; &gt; \n &lt; input type = &quot;submit&quot; id = &quot;submit&quot; name = &quot;submit&quot; value = &quot;Upload File Now&quot; &gt; \n &lt;\/ form &gt; \n &lt; p id = &quot;status&quot; &gt; &lt;\/ p &gt; \n &lt; script type = &quot;text\/javascript&quot; src = &quot;fileUpload.js&quot; &gt; &lt;\/ script &gt; \n &lt;\/ body &gt; \n &lt;\/ html &gt; \n\n<\/code><\/pre>\n<p>You now have a form with the following elements:<\/p>\n<ul>\n<li>An input field and a submit button.<\/li>\n<li>An action attribute\u2014within the form tag\u2014that points to the script that handles the upload.<\/li>\n<li>A method attribute that specifies the operation post undertaken by this form.<\/li>\n<li>An enctype attribute, whose value specifies the content type of the upload. multipart\/form-data is the value a native form submit needs in order to send file bytes. It\u2019s used only on a native submit: once the submit event is intercepted and a FormData object is sent instead, the browser sets the Content-Type and the multipart boundary on the request itself, and the attribute is ignored.<\/li>\n<li>An id attribute for both input fields, which handle the form elements with JavaScript.<\/li>\n<\/ul>\n<p><strong>Add the Cloudinary JavaScript library.<\/strong><\/p>\n<p>JavaScript plugins on Cloudinary facilitate image uploads to its server. Include them in your index.html file, like this:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>&lt;script src=&quot;https:\/\/upload-widget.cloudinary.com\/latest\/global\/all.js&quot; type=&quot;text\/javascript&quot;&gt;&lt;\/script&gt;\n<\/code><\/pre>\n<p>The latest path picks up current fixes on its own, and the documentation also shows a version-pinned path if you would rather control when the widget changes.<\/p>\n<pre class=\"js-syntax-highlighted\"><code>const widget = cloudinary.createUploadWidget(\n  {\n    cloudName: 'YOUR_CLOUD_NAME',\n    uploadPreset: 'YOUR_UPLOAD_PRESET',\n  },\n  (error, result) =&gt; {\n    if (error) {\n      console.error(error);\n      return;\n    }\n\n    if (result &amp;&amp; result.event === 'success') {\n      document.querySelector('#preview').src = result.info.secure_url;\n    }\n  }\n);\n\ndocument.querySelector('#open-widget').addEventListener('click', () =&gt; widget.open());\n\n<\/code><\/pre>\n<p>Add <code>&amp;lt;button type=&quot;button&quot; id=&quot;open-widget&quot;&gt;Upload&amp;lt;\/button&gt;<\/code> and <code>&amp;lt;img id=&quot;preview&quot; alt=&quot;&quot;&gt;<\/code> to the page for the widget to open from and write its result into. The widget gives you the file picker, drag and drop, previews, its own progress display and retries, in one script tag.<\/p>\n<p>The callback receives one result object and fires for several events, which is why the handler checks <code>result.event === 'success'<\/code> before reading <code>result.info<\/code>.<\/p>\n<p>Be sure to replace the <code>YOUR_CLOUD_NAME<\/code> and <code>YOUR_UPLOAD_PRESET<\/code> variables with their values from your Cloudinary dashboard. The API key and the API secret stay out of browser code: an unsigned upload needs only the cloud and preset names.<\/p>\n<h3>Post Directly to the Upload API With XMLHttpRequest<\/h3>\n<p>The widget draws its own interface. When the progress has to appear inside your own design instead, post to the Upload API with XMLHttpRequest and keep your own progress bar. The endpoint format for Cloudinary is<\/p>\n<pre class=\"js-syntax-highlighted\"><code>https:\/\/api.cloudinary.com\/v1_1\/&lt;cloud name&gt;\/&lt;resource_type&gt;\/upload\n<\/code><\/pre>\n<p>So for images it will look like:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>https:\/\/api.cloudinary.com\/v1_1\/YOUR_CLOUD_NAME\/image\/upload\n<\/code><\/pre>\n<p>The body is the same FormData object from the first example, plus the preset name.<\/p>\n<pre class=\"js-syntax-highlighted\"><code>const CLOUD_NAME = 'YOUR_CLOUD_NAME';\nconst UPLOAD_PRESET = 'YOUR_UPLOAD_PRESET';\n\nfunction uploadToCloudinary(file, onProgress) {\n  return new Promise((resolve, reject) =&gt; {\n    const body = new FormData();\n    body.append('file', file);\n    body.append('upload_preset', UPLOAD_PRESET);\n\n    const xhr = new XMLHttpRequest();\n\n    xhr.upload.addEventListener('progress', (event) =&gt; {\n      if (event.lengthComputable) {\n        onProgress(Math.round((event.loaded \/ event.total) * 100));\n      }\n    });\n\n    xhr.addEventListener('load', () =&gt; {\n      let payload;\n      try {\n        payload = JSON.parse(xhr.responseText);\n      } catch (e) {\n        reject(new Error('The response was not JSON.'));\n        return;\n      }\n\n      if (xhr.status === 200) {\n        resolve(payload);\n      } else {\n        reject(new Error('Upload failed with HTTP ' + xhr.status));\n      }\n    });\n\n    xhr.addEventListener('error', () =&gt; reject(new Error('Network error.')));\n\n    xhr.open('POST', 'https:\/\/api.cloudinary.com\/v1_1\/' + CLOUD_NAME + '\/image\/upload');\n    xhr.send(body);\n  });\n} \n\n<\/code><\/pre>\n<p>The response carries secure_url for display and public_id, which is the identifier to store in your own database. Use auto in place of image in the endpoint to let Cloudinary detect the resource type rather than assuming an image.<\/p>\n<h3>Signed vs Unsigned Uploads<\/h3>\n<table>\n  <tr>\n   <td>\n   <\/td>\n   <td><strong>Unsigned<\/strong>\n   <\/td>\n   <td><strong>Signed<\/strong>\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>What the browser sends<\/strong>\n   <\/td>\n   <td>The file and upload_preset\n   <\/td>\n   <td>The file, api_key, timestamp and signature\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Where the API secret lives<\/strong>\n   <\/td>\n   <td>Nowhere in the request\n   <\/td>\n   <td>Your server only\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Who can upload<\/strong>\n   <\/td>\n   <td>Anyone who learns the preset name\n   <\/td>\n   <td>Only callers your server issued a signature to\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Where the options are set<\/strong>\n   <\/td>\n   <td>On the preset\n   <\/td>\n   <td>In the signed request, or on the preset\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Extra moving part<\/strong>\n   <\/td>\n   <td>None\n   <\/td>\n   <td>An endpoint on your server that returns a signature\n   <\/td>\n  <\/tr>\n<\/table>\n<p>Use unsigned uploads when the preset\u2019s own restrictions are enough. Use signed uploads when the upload has to be tied to an authenticated user, or rate-limited.<\/p>\n<h3>Security of the Upload Path and Delivery<\/h3>\n<p>Where an upload lands is the part a security review asks about, so these are the specifics worth having to hand.<\/p>\n<ul>\n<li>Uploads post over HTTPS to api.cloudinary.com, and the widget and the Upload API use the same endpoint.<\/li>\n<li>After the upload, delivery can be restricted instead of left open. Adding the sign_url parameter produces a signed delivery URL, which is what authorizes access to <a href=\"https:\/\/cloudinary.com\/documentation\/control_access_to_media\">private and authenticated assets<\/a>. The same documentation is explicit about the limit of that control: a signed URL does not prevent link sharing.<\/li>\n<li>Uploading with the authenticated delivery type means the original file and any derived versions are accessible only through a signed URL, and on-the-fly transformations cannot be created for those assets.<\/li>\n<li>Strict transformations block transformation URLs that were not explicitly allowed. Once it is switched on, transformations can only be created through eager transformations, signed delivery URLs, allowed named transformations or allowed referral domains.<\/li>\n<\/ul>\n<p>For access that has to expire, token-based authentication adds a signed token through auth_token alongside sign_url. It takes either duration, the number of seconds the URL stays valid, or expiration, a UNIX timestamp. At least one of the two is required, and duration is ignored if both are given. The token\u2019s encryption key is not your API secret.<\/p>\n<h2>PHP Ajax File Upload to a Backend Server<\/h2>\n<p>To handle file uploads with AJAX and store the files on a backend server (e,g PHP Server), create an HTML form and two upload scripts: one written in JavaScript and the other in PHP.<\/p>\n<p>In your root directory, build an HTML form (an index.html file) with the following code, which contains the fields for file uploads:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-meta\">&lt;!DOCTYPE <span class=\"hljs-meta-keyword\">html<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"UTF-8\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>File Uploads With AJAX<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"file-form\"<\/span> <span class=\"hljs-attr\">action<\/span>=<span class=\"hljs-string\">\"fileUpload.php\"<\/span> <span class=\"hljs-attr\">method<\/span>=<span class=\"hljs-string\">\"post\"<\/span> <span class=\"hljs-attr\">enctype<\/span>=<span class=\"hljs-string\">\"multipart\/form-data\"<\/span>&gt;<\/span>\n        Upload a File:\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"file\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"myfile\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"myfile\"<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"submit\"<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"submit\"<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"submit\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"Upload File Now\"<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"status\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">script<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"text\/javascript\"<\/span> <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\"fileUpload.js\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">script<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><strong>Note the following:<\/strong><\/p>\n<ul>\n<li>The form contains an input field and a submit button.\n<ul>\n<li>The form tag has an action attribute that points to the script that will take care of the actual upload process. It also has a method attribute that specifies the kind of operation this form will undertake, which is post.<\/li>\n<li>An enctype attribute, whose value specifies the content type of the upload. multipart\/form-data is the value a native form submit needs in order to send file bytes. It is used only on a native submit: once the submit event is intercepted and a FormData object is sent instead, the browser sets the Content-Type and the multipart boundary on the request itself, and the attribute is ignored.<\/li>\n<li>An id attribute for both input fields, which handles the form elements with JavaScript.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>JavaScript AJAX File Upload Example<\/strong><\/p>\n<p>In your root directory, create a file called fileUpload.js with the following code:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>( function ( ) {\n var form = document .getElementById( 'file-form' );\n var fileSelect = document .getElementById( 'myfile' );\n var uploadButton = document .getElementById( 'submit' );\n var statusDiv = document .getElementById( 'status' );\n\n form.onsubmit = function ( event ) {\n event.preventDefault();\n\n statusDiv.innerHTML = 'Uploading . . . ' ;\n\n \/\/ Get the files from the input \n var files = fileSelect.files;\n\n \/\/ Create a FormData object. \n var formData = new FormData();\n\n \/\/Grab only one file since this script disallows multiple file uploads. \n var file = files[ 0 ]; \n\n \/\/Check the file type. \n if (!file.type.match( 'image.*' )) {\n statusDiv.innerHTML = 'You cannot upload this file because it's not an image.' ;\n return ;\n }\n\n if (file.size &gt;= 2000000 ) {\n statusDiv.innerHTML = 'You cannot upload this file because its size exceeds the maximum limit of 2 MB.' ;\n return ;\n }\n\n \/\/ Add the file to the AJAX request. \n formData.append( 'myfile' , file, file.name);\n\n \/\/ Set up the request. \n var xhr = new XMLHttpRequest();\n\n \/\/ Open the connection. \n xhr.open( 'POST' , '\/fileUpload.php' , true );\n \n\n \/\/ Set up a handler for when the task for the request is complete. \n xhr.onload = function ( ) {\n if (xhr.status === 200 ) {\n statusDiv.innerHTML = 'Your upload is successful..' ;\n } else {\n statusDiv.innerHTML = 'An error occurred during the upload. Try again.' ;\n }\n };\n\n \/\/ Send the data. \n xhr.send(formData);\n }\n})();\n\n<\/code><\/pre>\n<p>Step by step, the process proceeds as follows:<\/p>\n<p>Grab all the elements, i.e., the form, the file-input, and status div, as reflected in this code:<\/p>\n<pre class=\"js-syntax-highlighted\"><code> var form = document .getElementById( 'file-form' );\n var fileSelect = document .getElementById( 'myfile' );\n var statusDiv = document .getElementById( 'status' );\n\n<\/code><\/pre>\n<p>Call the form\u2019s onsubmit event. After the user has submitted the form, attach an event handler to the form:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>form.onsubmit = function ( event ) {\n\u2026.\n\n}\n\n<\/code><\/pre>\n<p>Get hold of the file specified by the user and, for a robust experience, keep that user informed of what\u2019s transpiring behind the scenes, like this:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>...\n\n statusDiv.innerHTML = 'Uploading . . . ' ;\n\n \/\/ Picking up files from the input . . . \n var files = fileSelect.files;\n\n \/\/ Uploading only one file; multiple uploads are not allowed. \n var file = files[ 0 ]; \n\n...\n\n<\/code><\/pre>\n<p>Create a form object, validate the size and type of the file to be uploaded, and add the file to form, like this:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\"><span class=\"hljs-comment\">\/\/ Create a FormData object.<\/span>\n<span class=\"hljs-keyword\">var<\/span> formData = <span class=\"hljs-keyword\">new<\/span> FormData();\n\n<span class=\"hljs-comment\">\/\/ Check the file type.<\/span>\n<span class=\"hljs-keyword\">if<\/span> (!file.type.match(<span class=\"hljs-string\">'image.*'<\/span>)) {\n  statusDiv.innerHTML = <span class=\"hljs-string\">'You cannot upload this file because it\u2019s not an image.'<\/span>;\n  <span class=\"hljs-keyword\">return<\/span>;\n}\n\n<span class=\"hljs-keyword\">if<\/span> (file.size &gt;= <span class=\"hljs-number\">2000000<\/span>) {\n  statusDiv.innerHTML = <span class=\"hljs-string\">'You cannot upload this file because its size exceeds the maximum limit of 2 MB.'<\/span>;\n  <span class=\"hljs-keyword\">return<\/span>;\n}\n\n<span class=\"hljs-comment\">\/\/ Add the file to the request.<\/span>\nformData.append(<span class=\"hljs-string\">'myfile'<\/span>, file, file.name);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Set up an AJAX request, open a connection, and listen for the onload event of the xhr object.<\/p>\n<pre class=\"js-syntax-highlighted\"><code> \/\/ Set up an AJAX request. \n var xhr = new XMLHttpRequest();\n\n \/\/ Open the connection. \n xhr.open( 'POST' , '\/fileUpload.php' , true );\n \n\n \/\/ Set up a handler for when the task for the request is complete. \n xhr.onload = function () {\n if (xhr.status === 200 ) {\n statusDiv.innerHTML = 'Your upload is successful. ';\n } else {\n statusDiv.innerHTML = 'An error occurred while uploading the file... Try again';\n }\n };\n\n \/\/ Send the Data.\n xhr.send(formData);\n\n<\/code><\/pre>\n<p>Here, you make a post request to fileUpload.php. And yes, you must still process the file on the back end, to which the AJAX request submits the file for processing.<\/p>\n<p>Before leveraging the preceding code for production, you must make provisions for several edge cases, for example, perform checks to ensure that only safe files are posted to your back end.<\/p>\n<p><strong>PHP script<\/strong><\/p>\n<p>Below is the script written in PHP.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"php\"><span class=\"hljs-meta\">&lt;?php<\/span>\n\n$currentDir = getcwd();\n$uploadDirectory = <span class=\"hljs-string\">\"\/uploads\/\"<\/span>;\n\n$errors = &#91;]; <span class=\"hljs-comment\">\/\/ Store all foreseen and unforeseen errors here.<\/span>\n\n$fileExtensions = &#91;<span class=\"hljs-string\">'jpeg'<\/span>, <span class=\"hljs-string\">'jpg'<\/span>, <span class=\"hljs-string\">'png'<\/span>]; <span class=\"hljs-comment\">\/\/ Allowed file extensions.<\/span>\n\n$fileName = $_FILES&#91;<span class=\"hljs-string\">'myfile'<\/span>]&#91;<span class=\"hljs-string\">'name'<\/span>];\n$fileSize = $_FILES&#91;<span class=\"hljs-string\">'myfile'<\/span>]&#91;<span class=\"hljs-string\">'size'<\/span>];\n$fileTmpName = $_FILES&#91;<span class=\"hljs-string\">'myfile'<\/span>]&#91;<span class=\"hljs-string\">'tmp_name'<\/span>];\n$fileType = $_FILES&#91;<span class=\"hljs-string\">'myfile'<\/span>]&#91;<span class=\"hljs-string\">'type'<\/span>];\n\n$fileExtension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));\n\n$uploadPath = $currentDir . $uploadDirectory . basename($fileName);\n\n<span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-keyword\">isset<\/span>($fileName)) {\n\n    <span class=\"hljs-keyword\">if<\/span> (!in_array($fileExtension, $fileExtensions)) {\n        $errors&#91;] = <span class=\"hljs-string\">\"This process does not support this file type. Upload a JPEG or PNG file only.\"<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">if<\/span> ($fileSize &gt; <span class=\"hljs-number\">2000000<\/span>) {\n        $errors&#91;] = <span class=\"hljs-string\">\"You cannot upload this file because its size exceeds the maximum limit of 2 MB.\"<\/span>;\n    }\n\n    <span class=\"hljs-keyword\">if<\/span> (<span class=\"hljs-keyword\">empty<\/span>($errors)) {\n\n        $didUpload = move_uploaded_file($fileTmpName, $uploadPath);\n\n        <span class=\"hljs-keyword\">if<\/span> ($didUpload) {\n            <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"The file \"<\/span> . basename($fileName) . <span class=\"hljs-string\">\" has been uploaded.\"<\/span>;\n        } <span class=\"hljs-keyword\">else<\/span> {\n            <span class=\"hljs-keyword\">echo<\/span> <span class=\"hljs-string\">\"An error occurred. Try again or contact your system administrator.\"<\/span>;\n        }\n\n    } <span class=\"hljs-keyword\">else<\/span> {\n\n        <span class=\"hljs-keyword\">foreach<\/span> ($errors <span class=\"hljs-keyword\">as<\/span> $error) {\n            <span class=\"hljs-keyword\">echo<\/span> $error . <span class=\"hljs-string\">\"\\n\"<\/span>;\n        }\n\n    }\n}\n\n<span class=\"hljs-meta\">?&gt;<\/span><\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Ensure you are running a PHP server:<\/p>\n<p>Now when you run that PHP app, it looks like this:<\/p>\n<p>In addition, note the following:<\/p>\n<ul>\n<li>The PHP script works for image files only.<\/li>\n<li>The file-size limit is 2 MB.<\/li>\n<\/ul>\n<p>Upload images to a dedicated file server in addition to the server in which your web app resides. Check out this <a href=\"https:\/\/github.com\/unicodeveloper\/cld-php-file-upload-proc\">source code<\/a> for a related tutorial.<\/p>\n<h3>How Do You Add an Upload Progress Bar?<\/h3>\n<p>Progress events for an upload fire on xhr.upload, not on the request object itself. MDN\u2019s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/XMLHttpRequest_API\/Using_XMLHttpRequest\">guide to using XMLHttpRequest<\/a> is explicit that the listeners have to be added before open() is called, or the progress events do not fire.<\/p>\n<p>Add a progress element to the form:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">progress<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"bar\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"0\"<\/span> <span class=\"hljs-attr\">max<\/span>=<span class=\"hljs-string\">\"100\"<\/span> <span class=\"hljs-attr\">hidden<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">progress<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Then attach the listener while the request is still being configured, before open():<\/p>\n<pre class=\"js-syntax-highlighted\"><code>const bar = document.querySelector('#bar');\nconst xhr = new XMLHttpRequest();\n\nxhr.upload.addEventListener('progress', (event) =&gt; {\n  if (!event.lengthComputable) {\n    \/\/ The total size is unknown, so no percentage can be calculated.\n    statusDiv.innerHTML = 'Uploading...';\n    return;\n  }\n\n  const percent = Math.round((event.loaded \/ event.total) * 100);\n  bar.hidden = false;\n  bar.value = percent;\n  statusDiv.innerHTML = percent + '% uploaded';\n});\n\nxhr.open('POST', '\/fileUpload.php');\nxhr.send(formData);\n\n<\/code><\/pre>\n<p>event.loaded is the number of bytes sent so far and event.total the number to send. When lengthComputable is false, the total length is not known and is reported as zero, so check it before dividing.<\/p>\n<h3>How Do You Cancel an Upload in Progress?<\/h3>\n<p>A large upload needs a way out. <code>xhr.abort()<\/code> cancels the request in flight, and the abort event on xhr.upload is where the interface resets. Add a <code>&amp;lt;button type=&quot;button&quot; id=&quot;cancel&quot;&gt;Cancel&amp;lt;\/button&gt;<\/code> next to the submit button for it to hang off.<\/p>\n<pre class=\"js-syntax-highlighted\"><code>\/\/ csrfToken comes from your page, for example a meta tag your template renders.\nlet current = null;\n\nfunction upload(file) {\n  const formData = new FormData();\n  formData.append('myfile', file, file.name);\n\n  const xhr = new XMLHttpRequest();\n  current = xhr;\n\n  xhr.upload.addEventListener('abort', () =&gt; {\n    statusDiv.innerHTML = 'Upload canceled.';\n  });\n\n  xhr.upload.addEventListener('error', () =&gt; {\n    statusDiv.innerHTML = 'The transfer failed before it completed.';\n  });\n\n  xhr.addEventListener('timeout', () =&gt; {\n    statusDiv.innerHTML = 'The upload timed out.';\n  });\n\n  xhr.addEventListener('load', () =&gt; {\n    current = null;\n  });\n\n  xhr.open('POST', '\/fileUpload.php');\n  xhr.timeout = 120000;\n  xhr.setRequestHeader('X-CSRF-Token', csrfToken);\n  xhr.send(formData);\n}\n\ndocument.querySelector('#cancel').addEventListener('click', () =&gt; {\n  if (current) current.abort();\n});\n\n<\/code><\/pre>\n<p>Three ordering rules apply here, and breaking any of them can lead to an issue without throwing an error:<\/p>\n<ol>\n<li>upload progress listeners go on before open()<\/li>\n<li>setRequestHeader() works only after open() and before send()<\/li>\n<li>xhr.timeout has to be set before send().<\/li>\n<\/ol>\n<p>A custom header such as X-CSRF-Token is also what turns a cross-origin upload into a preflighted request, so the endpoint\u2019s OPTIONS response has to allow that header.<\/p>\n<h3>How Do You Upload Multiple Files With AJAX?<\/h3>\n<p>The script above handles one file on purpose. To accept several, add multiple to the input and append each file under the same field name with a [] suffix, which is what makes PHP parse it as an array.<\/p>\n<pre class=\"js-syntax-highlighted\"><code>&lt;input type=&quot;file&quot; id=&quot;files&quot; name=&quot;files[]&quot; multiple&gt;\n Code language: HTML, XML ( xml )\nconst formData = new FormData();\n\nfor (const file of document.querySelector('#files').files) {\n  formData.append('files[]', file, file.name);\n}\n\n<\/code><\/pre>\n<p>On the PHP side, $_FILES[\u2018files\u2019] then holds parallel arrays, so $_FILES[\u2018files\u2019][\u2018tmp_name\u2019][0], [\u2018tmp_name\u2019][1] and so on, with a matching [\u2018error\u2019] entry per file.<\/p>\n<h3>Why the Client-Side Checks Are Not Enough<\/h3>\n<p>The accept attribute and the file.type.match() check above are interface conveniences. They tell the user what is wanted before they wait for an upload. They prove nothing, because a request built with curl never runs your JavaScript. Four holes close on the server:<\/p>\n<ul>\n<li>\n<strong>The extension is user input.<\/strong> Taking the extension from <code>$_FILES['myfile']['name']<\/code> lets a caller name a script <code>avatar.png<\/code> or <code>avatar.php.png<\/code>. Derive the extension from a type you verified instead.<\/li>\n<li>\n<strong>The type field is user input too.<\/strong> <code>$_FILES['myfile']['type']<\/code> is copied from the request\u2019s own part header. Read the type from the bytes on disk with the bundled fileinfo extension instead: <code>(new finfo(FILEINFO_MIME_TYPE))-&gt;file($fileTmpName)<\/code>.<\/li>\n<li>\n<strong>A verified image can still carry a payload.<\/strong> Type sniffing tells you the first bytes look like a JPEG, not that the rest is harmless. The control that works is storing the file where the web server will never execute it, which means a directory outside the document root rather than an \/uploads\/ folder under it.<\/li>\n<li>\n<strong>The client filename can collide.<\/strong> <code>basename()<\/code> handles path traversal, but two users uploading photo.jpg still overwrite each other. Generate the stored name yourself, for example with <code>bin2hex(random_bytes(16))<\/code>, and keep the original name in your database if you need to show it.<\/li>\n<\/ul>\n<p>Check <code>$_FILES['myfile']['error']<\/code> against <code>UPLOAD_ERR_OK<\/code> and call <code>is_uploaded_file()<\/code> before <code>move_uploaded_file()<\/code>. If you accept file types other than images, add a malware scan in front of storage, because neither PHP nor a type check is sufficient.<\/p>\n<h3>PHP Limits That Break Uploads Silently<\/h3>\n<p>These are PHP\u2019s documented defaults, from the <a href=\"https:\/\/www.php.net\/manual\/en\/ini.core.php\">core configuration list<\/a> in the manual. The third row is the one that produces the confusing bug report, because $_FILES arrives empty with no error code to inspect.<\/p>\n<table>\n  <tr>\n   <td><strong>Directive<\/strong>\n   <\/td>\n   <td><strong>Default<\/strong>\n   <\/td>\n   <td><strong>What happens when it is exceeded<\/strong>\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>file_uploads\n   <\/td>\n   <td>1\n   <\/td>\n   <td>Uploads are disabled entirely when it is switched off.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>upload_max_filesize\n   <\/td>\n   <td>2M\n   <\/td>\n   <td>The file appears in $_FILES with error set to UPLOAD_ERR_INI_SIZE.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>post_max_size\n   <\/td>\n   <td>8M\n   <\/td>\n   <td>$_POST and $_FILES are both empty. There is no per-file error code.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>max_file_uploads\n   <\/td>\n   <td>20\n   <\/td>\n   <td>Files past the limit are not present in $_FILES at all.\n   <\/td>\n  <\/tr>\n<\/table>\n<p>Keep post_max_size above upload_max_filesize, because the request body also carries the multipart headers and any other form fields. Your web server has its own ceiling as well, such as nginx\u2019s client_max_body_size, and the lowest of the three wins.<\/p>\n<h2>XMLHttpRequest vs Fetch vs jQuery $.ajax<\/h2>\n<p>All three send the same multipart\/form-data request. They differ in what they let you observe while it is in flight.<\/p>\n<table>\n  <tr>\n   <td><strong>Approach<\/strong>\n   <\/td>\n   <td><strong>Upload progress<\/strong>\n   <\/td>\n   <td><strong>Cancel<\/strong>\n   <\/td>\n   <td><strong>Dependency<\/strong>\n   <\/td>\n   <td><strong>Use it when<\/strong>\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>XMLHttpRequest and FormData\n   <\/td>\n   <td>Yes, through progress events on xhr.upload\n   <\/td>\n   <td>xhr.abort()\n   <\/td>\n   <td>None\n   <\/td>\n   <td>You need a progress bar. This is still the way to get one.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>fetch and FormData\n   <\/td>\n   <td>No upload progress event\n   <\/td>\n   <td>AbortController\n   <\/td>\n   <td>None\n   <\/td>\n   <td>The upload is small enough that a spinner is honest, and you want promises.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>jQuery $.ajax and FormData\n   <\/td>\n   <td>Yes, by returning your own XHR from the xhr option\n   <\/td>\n   <td>abort() on the returned jqXHR\n   <\/td>\n   <td>jQuery\n   <\/td>\n   <td>jQuery is already on the page and you do not want two request styles in one codebase.\n   <\/td>\n  <\/tr>\n  <tr>\n   <td>Hosted uploader or widget\n   <\/td>\n   <td>Built in\n   <\/td>\n   <td>Built in\n   <\/td>\n   <td>A script tag or a package\n   <\/td>\n   <td>You want the picker, retries and validation handled, and you accept a vendor in the upload path.\n   <\/td>\n  <\/tr>\n<\/table>\n<p>The fetch version is the shortest:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>async function upload(file) {\n  const formData = new FormData();\n  formData.append('myfile', file, file.name);\n\n  const response = await fetch('\/fileUpload.php', { method: 'POST', body: formData });\n\n  if (!response.ok) {\n    throw new Error('Upload failed with HTTP ' + response.status);\n  }\n\n  return response.json();\n}\n\n<\/code><\/pre>\n<p>fetch resolves as soon as the response headers arrive and exposes no event for bytes sent, which is why a progress bar built on fetch can only guess. For a real percentage, use XMLHttpRequest for the upload and keep fetch for everything else.<\/p>\n<p>The jQuery version needs two settings that are easy to miss:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>$('#file-form').on('submit', function (event) {\n  event.preventDefault();\n\n  $.ajax({\n    url: '\/fileUpload.php',\n    type: 'POST',\n    data: new FormData(this),\n    processData: false,  \/\/ Do not let jQuery serialize FormData into a string.\n    contentType: false,  \/\/ Let the browser set multipart\/form-data and the boundary.\n    xhr: function () {\n      const xhr = $.ajaxSettings.xhr();\n      xhr.upload.addEventListener('progress', onProgress);\n      return xhr;\n    }\n  });\n});\n\n<\/code><\/pre>\n<p>In this code:<\/p>\n<ul>\n<li>\n<strong>processData<\/strong>: false stops jQuery turning the FormData object into a query string, which drops the file contents.<\/li>\n<li>\n<strong>contentType:<\/strong> false stops it setting a Content-Type without a boundary.<\/li>\n<li>\n<strong>new FormData(this)<\/strong> picks up the file input on its own, because the input has a name attribute.<\/li>\n<\/ul>\n<h2>AJAX File Upload Tools Compared<\/h2>\n<p>The comparison that matters is not library against service. It is how much of the upload path you want to own.<\/p>\n<table>\n  <tr>\n   <td><strong>Tool<\/strong>\n   <\/td>\n   <td><strong>What it is<\/strong>\n   <\/td>\n   <td><strong>Progress interface<\/strong>\n   <\/td>\n   <td><strong>Server code you still write<\/strong>\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>XMLHttpRequest and FormData<\/strong>\n   <\/td>\n   <td>No dependency, about 25 lines\n   <\/td>\n   <td>You build it\n   <\/td>\n   <td>Endpoint, validation, storage, resizing, delivery\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Dropzone.js<\/strong>\n   <\/td>\n   <td>Open-source drag-and-drop upload component for the browser\n   <\/td>\n   <td>Included\n   <\/td>\n   <td>Everything on the server\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Uppy<\/strong>\n   <\/td>\n   <td>Open-source JavaScript file uploader for the browser\n   <\/td>\n   <td>Included\n   <\/td>\n   <td>Everything on the server\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Filestack<\/strong>\n   <\/td>\n   <td>Hosted file upload and delivery service with a picker\n   <\/td>\n   <td>Included\n   <\/td>\n   <td>None for the upload itself\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Uploadcare<\/strong>\n   <\/td>\n   <td>Hosted file upload, storage and delivery service\n   <\/td>\n   <td>Included\n   <\/td>\n   <td>None for the upload itself\n   <\/td>\n  <\/tr>\n  <tr>\n   <td><strong>Cloudinary Upload API or upload widget<\/strong>\n   <\/td>\n   <td>Hosted upload, plus image and video transformation and CDN delivery\n   <\/td>\n   <td>Included in the widget, or build your own against the Upload API\n   <\/td>\n   <td>None for the upload itself\n   <\/td>\n  <\/tr>\n<\/table>\n<p>Dropzone.js and Uppy replace the picker and the progress interface, and the server work does not go away. Filestack, Uploadcare and Cloudinary replace the server work, and the difference between them is what happens to the file afterward. Cloudinary\u2019s answer is transformation and delivery of images and video.<\/p>\n<h3>What Cloudinary Doesn\u2019t Do<\/h3>\n<ul>\n<li>\n<strong>It doesn\u2019t scan files for viruses.<\/strong> The moderation add-ons judge image and video content, which is not an antivirus pass over arbitrary file types.<\/li>\n<li>\n<strong>It doesn\u2019t authenticate users.<\/strong> An unsigned preset is open to anyone who learns the name, so abuse control means a signed flow, or your own endpoint in front of it.<\/li>\n<li>\n<strong>It doesn\u2019t keep the data on your own infrastructure.<\/strong> If a requirement says the file must never leave hardware you control, the PHP handler above is the right answer, not a hosted service like Cloudinary.<\/li>\n<li>\n<strong>The widget doesn\u2019t expose its progress to your own interface.<\/strong> When the percentage has to appear inside your design, post to the Upload API with XMLHttpRequest instead.<\/li>\n<li>\n<strong>It\u2019s built around media.<\/strong> Arbitrary files can be stored as raw resources, but the transformation and optimization features apply to images and video.<\/li>\n<\/ul>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>The decision underneath all of this is simple. An AJAX file upload is a FormData object and about 25 lines of JavaScript, and the work is in what surrounds it: a progress bar that reports the transfer rather than the outcome, a cancel path, and a server that treats every field the browser sent as untrusted. Write that handler when the file has to stay on infrastructure you control. When it does not, posting straight to the Upload API with XMLHttpRequest keeps your own progress bar and removes the storage, validation and delivery work.<\/p>\n<p>Uploading AJAX files with Cloudinary is a cakewalk. Even though mastering AJAX technologies could be challenging, you can take advantage of them readily with the Cloudinary library for your app. Give it a try: <a href=\"https:\/\/cloudinary.com\/users\/register\/free\">signing up for Cloudinary<\/a> is free.<\/p>\n<h2><strong><a href=\"#bookmark=id.syiuqoplk96y\">Want to Learn More About File Uploads?<\/a><\/strong><\/h2>\n<ul>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/automating_file_upload_and_sharing\">Automating File Upload and Sharing<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/file_upload_with_php\">Uploading PHP Files and Rich Media the Easy Way<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/impressed_by_whatsapp_technology_build_a_whatsapp_clone_with_image_and_video_upload\">Impressed by WhatsApp technology? Clone WhatsApp Technology to Build a File Upload Android App<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/direct_image_uploads_from_the_browser_to_the_cloud_with_jquery\">Direct Image Uploads From the Browser to the Cloud With jQuery<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/file_upload_with_angular_or_angularjs_to_cloudinary\">File Upload With Angular to Cloudinary<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/uploading_vue_files_and_rich_media_in_two_easy_steps\">Uploading Vue Files and Rich Media in Two Easy Steps<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/node_js_file_upload_to_a_local_server_or_to_the_cloud\">Node.js File Upload To a Local Server Or to the Cloud<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/laravel_file_upload_to_a_local_server_or_to_the_cloud\">Laravel File Upload to a Local Server Or to the Cloud<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/javascript_file_upload_to_cloudinary\">JavaScript File Upload in Two Simple Steps<\/a>\n<\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":21484,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1],"tags":[426,119,263],"class_list":["post-21483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-featured","tag-file-upload","tag-sdk"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.3 (Yoast SEO v28.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>AJAX File Upload - Quick Tutorial and Time Saving Tips<\/title>\n<meta name=\"description\" content=\"This step-by step guide walks you through the basic ajax file upload process, with examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AJAX File Upload - Quick Tutorial and Time Saving Tips\" \/>\n<meta property=\"og:description\" content=\"This step-by step guide walks you through the basic ajax file upload process, with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-30T23:21:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-04T20:48:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"1540\" \/>\n\t<meta property=\"og:image:height\" content=\"847\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips\",\"datePublished\":\"2022-06-30T23:21:00+00:00\",\"dateModified\":\"2026-11-04T20:48:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax\"},\"wordCount\":10,\"publisher\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649720625\\\/Web_Assets\\\/blog\\\/Ajax-Blog-Cover_2000x1100\\\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA\",\"keywords\":[\"Featured\",\"File-upload\",\"SDK\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax\",\"name\":\"AJAX File Upload - Quick Tutorial and Time Saving Tips\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649720625\\\/Web_Assets\\\/blog\\\/Ajax-Blog-Cover_2000x1100\\\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA\",\"datePublished\":\"2022-06-30T23:21:00+00:00\",\"dateModified\":\"2026-11-04T20:48:40+00:00\",\"description\":\"This step-by step guide walks you through the basic ajax file upload process, with examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#primaryimage\",\"url\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649720625\\\/Web_Assets\\\/blog\\\/Ajax-Blog-Cover_2000x1100\\\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA\",\"contentUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649720625\\\/Web_Assets\\\/blog\\\/Ajax-Blog-Cover_2000x1100\\\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA\",\"width\":1540,\"height\":847,\"caption\":\"Image of computer screen showing Ajax upload file bursting out\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/file_upload_with_ajax#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/cloudinary.com\\\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649718331\\\/Web_Assets\\\/blog\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\\\/\\\/res.cloudinary.com\\\/cloudinary-marketing\\\/images\\\/f_auto,q_auto\\\/v1649718331\\\/Web_Assets\\\/blog\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\\\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\\\/\\\/cloudinary.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"AJAX File Upload - Quick Tutorial and Time Saving Tips","description":"This step-by step guide walks you through the basic ajax file upload process, with examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","og_locale":"en_US","og_type":"article","og_title":"AJAX File Upload - Quick Tutorial and Time Saving Tips","og_description":"This step-by step guide walks you through the basic ajax file upload process, with examples.","og_url":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","og_site_name":"Cloudinary Blog","article_published_time":"2022-06-30T23:21:00+00:00","article_modified_time":"2026-11-04T20:48:40+00:00","og_image":[{"width":1540,"height":847,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","type":"image\/jpeg"}],"twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax"},"author":{"name":"","@id":""},"headline":"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips","datePublished":"2022-06-30T23:21:00+00:00","dateModified":"2026-11-04T20:48:40+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax"},"wordCount":10,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","keywords":["Featured","File-upload","SDK"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","url":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","name":"AJAX File Upload - Quick Tutorial and Time Saving Tips","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","datePublished":"2022-06-30T23:21:00+00:00","dateModified":"2026-11-04T20:48:40+00:00","description":"This step-by step guide walks you through the basic ajax file upload process, with examples.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/file_upload_with_ajax"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","width":1540,"height":847,"caption":"Image of computer screen showing Ajax upload file bursting out"},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog"},{"@type":"ListItem","position":2,"name":"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":""}]}},"parsely":{"version":"1.1.0","canonical_url":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","meta":{"@context":"https:\/\/schema.org","@type":"NewsArticle","headline":"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips","url":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax","mainEntityOfPage":{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA&w=150&h=150&crop=1","image":{"@type":"ImageObject","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA"},"articleSection":"Uncategorized","author":[],"creator":[],"publisher":{"@type":"Organization","name":"Cloudinary Blog","logo":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA"},"keywords":["featured","file-upload","sdk"],"dateCreated":"2022-06-30T23:21:00Z","datePublished":"2022-06-30T23:21:00Z","dateModified":"2026-11-04T20:48:40Z"},"rendered":"<meta name=\"parsely-title\" content=\"AJAX File Upload &#8211; Quick Tutorial and Time Saving Tips\" \/>\n<meta name=\"parsely-link\" content=\"https:\/\/cloudinary.com\/blog\/file_upload_with_ajax\" \/>\n<meta name=\"parsely-type\" content=\"post\" \/>\n<meta name=\"parsely-image-url\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA&w=150&amp;h=150&amp;crop=1\" \/>\n<meta name=\"parsely-pub-date\" content=\"2022-06-30T23:21:00Z\" \/>\n<meta name=\"parsely-section\" content=\"Uncategorized\" \/>\n<meta name=\"parsely-tags\" content=\"featured,file-upload,sdk\" \/>","tracker_url":"https:\/\/cdn.parsely.com\/keys\/cloudinary.com\/p.js"},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649720625\/Web_Assets\/blog\/Ajax-Blog-Cover_2000x1100\/Ajax-Blog-Cover_2000x1100.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=21483"}],"version-history":[{"count":12,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21483\/revisions"}],"predecessor-version":[{"id":40650,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21483\/revisions\/40650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/21484"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=21483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=21483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=21483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}