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
CharlesDouCharlesDou 

Uploading an image using visualforce page but getting "Authorization Required " error everytime.

Hi everybody:

 

I am trying to write a visualforce and let the customer to upload an image. The code is:

 

VF code:

<label>Optional: Upload Image</label><apex:inputFile value="{!body}" fileName="{!fileName}" styleclass="apexinput"/>
<apex:CommandButton value="Save" action="{!Upload}"/>

 Apex Controller:

 

//definitions
    public Document doc{get;set;}
    public Blob body{get;set;}
    public String fileName{get;set;}

public pageReference Upload(){
//relative code
doc.body = body;
doc.Name = fileName;
insert doc;
}

 Why am I getting the  "Authorization Required " error everytime? Please Help. Thank you all.

 

Best Answer chosen by Admin (Salesforce Developers) 
colemabcolemab

If this is on a public VF page (i.e. not authenticated), then you are most likely getting the Authorization Required error instead of the actual error message (that would appear to authenticated users).

 

Errors don't show to public users for security reasons.

 

Login to your org and access the page via the /apex/YOURPAGENAMEHERE url and re-try to get the actual error message.

 

From your code, it looks like your file is being transmitted as part of the view state.   This is because it isn't tranisent and/or doesn't have a finally block to clear it between page loads.  

 

So I think your error might actually be viewstate exceeded.    Anyway, reply back with your actual error message.

All Answers

colemabcolemab

If this is on a public VF page (i.e. not authenticated), then you are most likely getting the Authorization Required error instead of the actual error message (that would appear to authenticated users).

 

Errors don't show to public users for security reasons.

 

Login to your org and access the page via the /apex/YOURPAGENAMEHERE url and re-try to get the actual error message.

 

From your code, it looks like your file is being transmitted as part of the view state.   This is because it isn't tranisent and/or doesn't have a finally block to clear it between page loads.  

 

So I think your error might actually be viewstate exceeded.    Anyway, reply back with your actual error message.

This was selected as the best answer
CharlesDouCharlesDou

Yes, I just figured it out and the problem is just what you said. Thanks a lot.