This is what we did in the VF Page. as we understand when using the FormData with the file in it, it basically as we pressed sibmit button. what we are missing is how in the controller we should get the file and convert it to document so we can attach the file to an object like Account or any other object we would like. eventually we would like to use drag & drop of html 5 to upload files... hope for any help to show us how we could get the file in the controller according to our sample TIA", "answerCount": 1, "upvoteCount": 0, "datePublished": "2013-10-28T07:30:48.000Z", "author": { "@type": "Person", "name": "Bitya Yahav", "url": "https://trailblazers.salesforce.com/profileView?u=005300000098N3aAAE", "affiliation": { "@type": "Organization", "name": "LLN IT Solutions" } }, "suggestedAnswer": [ { "@type": "Answer", "text": "Hello Bitya,   May I suggest also reposting this on the the developer forum at developer.force.com .  Thanks.", "upvoteCount": 0, "url": "https://trailhead.salesforce.com/trailblazer-community/feed/0D54S00000A7jZ9SAJ", "datePublished": "2013-11-01T13:45:27.000Z", "author": { "@type": "Person", "name": "Marija Jovanovic", "url": "https://trailblazers.salesforce.com/profileView?u=00530000009Ym5NAAS", "affiliation": { "@type": "Organization", "name": "Salesforce.com" } } } ] } }
Skip to main content

The new xmlhttprequest is now has capibility to upload files from the client (javascript) to the sever (controller) with the help of FormData object.

this is our partial sample we trying to do

in the VisualForce page we did

 

 

<input type="file" id="files" name="files[]" multiple="true" />

<script>

 

         document.getElementById('files').addEventListener('change', handleFileSelect, false);

          function handleFileSelect(evt) {

 

                  for (var i = 0, f; f = files[i]; i++) {

 

                       uploadFile(f);

 

                  }

 

          }

 

          

 

          function uploadFile(file) {

 

 

                      var formData = new FormData();

 

                      formData.append("myfile", file);

 

 

                       var xhr = new XMLHttpRequest();

 

                      

 

                        xhr.onreadystatechange = function(e) {

 

                             if (xhr.readyState == 4) {

 

                             }

 

                        }

 

                         

 

                        xhr.open("POST", "/apex/vf_DragAndDrop", true);

 

                        xhr.setRequestHeader("X_FILENAME", file.name);

 

                        xhr.send(formData);

 

                };

 

           }

 

</script>

 

 

This is what we did in the VF Page.

 

as we understand when using the FormData with the file in it, it basically as we pressed sibmit button.

 

 

what we are missing is how in the controller we should get the file and convert it to document so we can attach the file to an object like Account or any other object we would like.

eventually we would like to use drag & drop of html 5 to upload files...

hope for any help to show us how we could get the file in the controller according to our sample

 

TIA

1 answer
0/9000