You need to sign in to do that
Don't have an account?
bob_buzzard
InputFile and file name length
I'm using the apex InputFile standard component to allow users to attach images to one of my custom objects.
There seems to be a limit on the file name size, but I can't find anything in the docs or force sites to confirm this.
If the file name is greater than 81 characters, I get redirected to the salesforce "an error has occurred" page, but I don't get any warning emails etc., nor can I trap this error as it is happening before hitting my controller.
Has anyone else seen this?
No sure if still an issue as this has been not active for a while, but this is the solution I found.
Instead of using your public attachment to set the value and filename of the inputfile tag, example:
<apex:inputFile value="{!att.body}" fileName="{!att.Name}" />
Use two public fields on created on the controller, example:
public Blob attachmentBody {get; set;}
public String attachmentName {get; set;}
Then in the V-Force page use:
<apex:inputFile value="{!attachmentBody}" fileName="{!attachmentName}" />
Then on save.
Attachment newAtt = new Attachment();
newAtt.name = attachmentName;
newAtt.body = attachmentBody;
newAtt.parentID = 'Put parent object ID here'
insert newAtt;
I never figured out why exactly it caused issues, yhe same file that was throwing the exception message on a custom visual force page, uploaded fine on the salesforce interface for uploading an attachment. This worked for me and I hope it helps.
All Answers
Hai
I think Document Rules will be same here also .
Document Rules
1)You can upload documents that have file names of up to 255 characters
including the extension.
2)The size limit for any document you upload is 5 MB.
The maximum size for a custom-app logo is 20 KB.
Regards
Thanga
I have the same problem, inputFile is limiting the filename to 80 characters. I tried using a string to capture the filename but it is still null in the controller. Was anyone able to fix this to use 255 characters or more for a filename? Or can I check for a filename longer than 80 and prompt the user? I can't seem to think of a way to do that since the filename is null in the controller, javascript maybe?
THANKS!
No sure if still an issue as this has been not active for a while, but this is the solution I found.
Instead of using your public attachment to set the value and filename of the inputfile tag, example:
<apex:inputFile value="{!att.body}" fileName="{!att.Name}" />
Use two public fields on created on the controller, example:
public Blob attachmentBody {get; set;}
public String attachmentName {get; set;}
Then in the V-Force page use:
<apex:inputFile value="{!attachmentBody}" fileName="{!attachmentName}" />
Then on save.
Attachment newAtt = new Attachment();
newAtt.name = attachmentName;
newAtt.body = attachmentBody;
newAtt.parentID = 'Put parent object ID here'
insert newAtt;
I never figured out why exactly it caused issues, yhe same file that was throwing the exception message on a custom visual force page, uploaded fine on the salesforce interface for uploading an attachment. This worked for me and I hope it helps.
That works fine if you are saving the file as an attachment but there is still no way to set the file name if a user navigates directly to a PDF enabled Visualforce page.
This is a great workaround KenN, works nicely for manual uploads by user