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
bob_buzzardbob_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?

Best Answer chosen by Admin (Salesforce Developers) 
KenNKenN

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

thangasan@yahoothangasan@yahoo

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

bob_buzzardbob_buzzard
The size limit is the same, but I can't get near to the 255 characters for the file name.  Even with all the directory information (c:\documents and settings etc.) the name is only 197 characters, but it blows up.
agum34agum34

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?

 

 

<apex:inputFile value="{!contract.body}" fileName="{!contractName}"/>

public String contractName {get;set;}
 
public Attachment
  get {
      if (contract == null) {
            contract = new Attachment();
       }
      return contract;
  }
  set;
}

THANKS!

KenNKenN

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.

This was selected as the best answer
TehNrdTehNrd

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.

veevaveeva

This is a great workaround KenN, works nicely for manual uploads by user