function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tmax8200tmax8200 

Help passing a file name as a parameter through the URL in a POST request.

Hi,

 

I'm trying to pass a parameter through the URL of a page doing a POST request. The parameter is the name of a file I'm uploading to amazon s3. I was hoping this would work  

 

CONTROLLER:

Public String fileName {get; set;}

 

VF:

<input type="hidden" name="success_action_redirect" value="xxx?q={!fileName}"/>

<input name="file" type="file" fileName="{!fileName}"/> 

 

but the parameter comes up blank on the next page. I get this error

 

<Error>
<Code>MaxPostPreDataLengthExceeded</Code>

<Message>
Your POST request fields preceeding the upload file was too large.
</Message>

 

when I try this

 

<input name="{!fileName}" type="file"/>

 

Thanks!

 

Max

Best Answer chosen by Admin (Salesforce Developers) 
tmax8200tmax8200

Turned out that it was impossible. Had to send the filename to amazon s3 concatenated to the ID which was what I actually wanted to call the file. Filename + ID were returned in the response for the next page. 

All Answers

*werewolf**werewolf*

Well that type of input is literally posting the entire file, not just the filename.  Is that what you want?  How big is this file that you're trying to post?  (Evidently too big for Visualforce to handle it)

tmax8200tmax8200

Sending the file is not the problem. I want to pass the name of the file eg. example.txt as a parameter through the URL. But, to answer your question, the file's are up to 5gb.

*werewolf**werewolf*

Well you can do that with an input type="text" or something but not with a file input -- the file input will send the whole file.

tmax8200tmax8200

Sorry, I think I have not explained this very well. I am trying send a file to storage and pass the name of the file through the URL to the page that shows up after the file is sent.

*werewolf**werewolf*

OK, but you want your Visualforce page to be able to receive this file and store it?

tmax8200tmax8200

I'm sending the file to an external storage site (amazon s3). There's no problem with sending the file. What I need to do is keep the name of the file and pass it through the URL so it can be used in the page that shows after someone hits "submit".

*werewolf**werewolf*

OK, what page are you posting to?  Is that page then redirecting you back to your Visualforce page?

tmax8200tmax8200

I'm using a POST request to send the file to amazon and then being redirected to a new page using a success action redirect. You know how in visualforce you can do this in a file submit <apex:inputFile value="{!fileContent}" fileName="{!fileName}" /> assuming fileName is defined in the controller. I want to do this same thing with a POST request.

*werewolf**werewolf*

OK, but really the key is in the redirect, which that Visualforce inputFile tag is abstracting for you.  You're posting the file to Amazon and Amazon sends the browser back to your page -- is there a way to get it to put some information in the querystring or something during that redirect?

tmax8200tmax8200

Turned out that it was impossible. Had to send the filename to amazon s3 concatenated to the ID which was what I actually wanted to call the file. Filename + ID were returned in the response for the next page. 

This was selected as the best answer
*werewolf**werewolf*

Well install the Live Headers addon for Firefox, post a file, and you can see what exactly is getting posted.  That should help you track down what you need.