3

i am working on a need where in a text file needs which is uploaded, needs to be processed in the controller. We are uploading and displaying the uploaded file in the UI and the same needs to be passed to the controller in the next step.

I am using Java script remoting to pass the file from the UI to the controller. It was all working fine but noticed if i give a file of length greater than 1000000 length i get the below error. Is there a way we can avoid this and pass the file using Remoting.

Visualforce Remoting Exception: Input too long. [0, 1000000]

Below is my snippet

Visualforce.remoting.Manager.invokeAction(
                        '{!$RemoteAction.Translate.RunTranslation}',
                        '{!JSENCODE(sProcessedFile)}', 
                        '{!SourceLanguageName}', 
                        strUser,
                        '{!SourceLanguageCode}',
                       function(result, event){
                                if (event.status) {
                                    jobid = result;
                                    readyProgressbar(result);
                                } 
                                else if (event.type === 'exception') {
                                    alert('Exception 1'+event.message);
                                } 
                            }, 
                            {escape: true}
                        );

1 Answer 1

3

There is a very similar question at HTML Input FIle -> Javascript -> to SF Attachment or Richtext Field.

One suggestion there is to switch to using an apex action function instead.

E.g.

Visualforce:

<apex:actionfunction name="af_submitFile" action="{!submitFile}" >
    <apex:param name="fileData" value="" assignTo="{!fileData}"/>
</apex:actionfunction>

Javascript:

af_submitFile(base64EncodedFile);

Apex Controller:

public string fileData {get;set;}

public void submitFile(){

    Blob fileDataBlob = blob.valueOf(imageData);
    // Do something with the file
}
2
  • thanks a lot for your reply @daniel, i tried using actionfunction but then i am actually needing to poll a server every 3 seconds to display the result status of a batch job. When i use actionfunction and bind it with actionpoller there seems to be a limitation of minimum polling time of 5 secs but with JS Remoting i get to refresh with 2 seconds too and give the users a feel of live data update. Also my assumption was if we use JS remoting we dont use view state but using action methods consumes view state. I can convince the client for the 5sec wait but is this best practise than JSremote? Commented May 16, 2014 at 20:28
  • @Anil Is monitoring the status of the batch job directly related to the submission of the file? To me a batch Apex job seems like a different thing entirely. Might be an issue with terminology. That said, I don't know of an easy way past the JS remoteing size limit. Maybe vary the usage based on the file size? Commented May 17, 2014 at 9:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .