You need to sign in to do that
Don't have an account?
Simon Repar
POST a file to VisualForce page
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)
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/)):
Do you have any ideas what I am doing wrong or it is completely impossible to achieve that?
Thank you.
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.
http://peterknolle.com/file-upload-lightning-component/
Thank you Bob for the link, I will take a look.
Did you ever manage to find a solition for POSTing a file to a Visualforce page? I have a third party who needs to send a CSV file to our SF Org and their only option to use a HTTP POST so the <apex:inpufFile /> method isn't an option for me.
Thanks
Mark
no, I didn't find a solution to that problem, but I managed to implement solution which includes FileReader API (which is HTML 5 technology) and I sacrificed compatibility for IE <=9.
So the process would be:
1. reading a file through File/FileReader API
2. implementing REST webservice for accepting String data type (if you need ws public you must expose that controller to sites).
3. sending a file to REST ws with javascript and encoding accordingly (base64 stuff).
Hope it helps.