Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Our organization has a Visualforce page, exposed through sites, that allows users to upload a file. When uploading .pdf files, users receive the generic authorization required error. They can, however, upload other file types without a problem. Is there any particular restriction on the uploading of .pdf files that I'm not aware of? I've checked the debug logs but there were no errors that I could see. Any help on how to troubleshoot this would be much appreciated.

Edit: The error I get when viewing the page as a logged in Salesforce user is below.

*Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 156.188KB *

share|improve this question
    
Are there any dots in your filename other than before the pdf file extension? –  bigassforce Feb 20 '13 at 23:09
    
BTW are you already logging the Site user? –  bigassforce Feb 20 '13 at 23:09
1  
No dots in the .pdf filename. I am logging the site user but the log comes up error free. –  dannymorty Feb 21 '13 at 15:39
    
@dannymorty Hi Danny. I want to allow users to upload PDFs and have it stored in an sObject. Were you perhaps using the text(rich) field and storing the PDFs in there? Thank you! –  Matthew Moisen May 3 '13 at 19:14

2 Answers 2

up vote 3 down vote accepted

You have to clear out the body of the object after you have saved it. I am guessing you are using an Attachment object, so if your variable is named attach try this:

attach.Body = null;

This needs to be done right after you save it (I would do it in a try/catch/finally block like:

Savepoint sp = Database.setSavepoint();
try{
    insert attach;
}catch(Exception e){
    System.debug('An error occurred while saving an attachment. Exception: ' + e);
    Database.rollback(sp);
}finally{
    attach.Body = null;
}

The problem is your controller is trying to serialize the Blob of the body and it is way too large for your View State. As a novice developer, I would suggest reading up on the View State. It is really useful info to know.

share|improve this answer
    
Thanks Jesse and @LaceySnr. I really appreciate both of you taking the time to lend a hand. –  dannymorty Feb 21 '13 at 22:39

Try uploading the file from the page inside the org as a logged in user, chances are you'll see an error message that makes a lot more sense.

Is it any PDF, or is it size related — there's maximum file size (5MB I think) so if the PDF being tested happens to be larger than that then you've probably hit the nail on the head.

share|improve this answer
    
It is in fact any pdf. My test file was 180kb. As for logging into the org and trying the same thing, I'm getting a seemingly unrelated error that I'm trying to get to the root of. I'll update as soon as I can. –  dannymorty Feb 20 '13 at 22:30
4  
What is that error? Chances are it's not unrelated but getting in the way. The exception page isn't visible to portal users by default so they see the authorisation issue when the system is trying to report an error, so the error you see as a regular user is likely the culprit. –  LaceySnr Feb 20 '13 at 22:53
    
Ha! I realized that I was incorrectly forming the URL and that is why I was getting the error I was seeing. That being said, this is the error I got when correctly formatting the URL. <br/> Maximum view state size limit (135KB) exceeded. Actual view state size for this page was 156.188KB. <br/> Any help on this error would be great. As you can probably tell, I'm quite a novice developer. View state is not something I'm particularly familiar with. –  dannymorty Feb 21 '13 at 16:20
1  
Jesse has your answer ;) –  LaceySnr Feb 21 '13 at 22:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.