• Mark Allerton
  • NEWBIE
  • 0 Points
  • Member since 2014


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi everyone.

I know that it is possible to POST data (text) to VF page and than fetch them through ApexPages.getCurrentPage().getParameters(), but I didn't find a way to do the same if I POST a file and data is multipart/form-data encoded.

This is my piece of sample code:

VF page (page which receive a file after POST)
<apex:page controller="PostFile_Controller" sidebar="false" showheader="false"  applyBodyTag="false" applyHtmlTag="false" cache="false" action="{!react}">

</apex:page>
Controller:
public class PostFile_Controller {

    public PageReference react() {
	
		//get all parameters
		system.debug(ApexPages.currentPage().getParameters());
		
		//get all headers
		system.debug(ApexPages.currentPage().getHeaders());
	}	
}

VF page which POST a file (this is just an example, I actually use jquery file upload plugin (http://blueimp.github.io/jQuery-File-Upload/)):
var formData = new FormData($('form')[0]);
$.ajax({
	url: '/apex/postfile',  //Server script to process data
	type: 'POST',
	xhr: function() {  // Custom XMLHttpRequest
		var myXhr = $.ajaxSettings.xhr();
		return myXhr;
	},
	// Form data
	data: formData
});


Do you have any ideas what I am doing wrong or it is completely impossible to achieve that? 

Thank you.