this my vf code: <apex:page Controller="uploadPhoto" sidebar="false" showHeader="false"> <apex:form > <apex:pageBlock title="Attach File" >
<h1>1.Select the File</h1> <p>Type the path of the file or click the Browse button to find the file </p> <apex:inputFile value="{!file}"/> <br/> <apex:commandButton value="Browse" action="{!loadPhoto}"/> <br/>
<h1>2.Click the "Attach File" button.</h1> <p>Repeat steps 1 and 2 to attach multiple files </p> <p>(When the upload is completed the file information will appear below)</p><br/> <apex:commandButton value="Attach File" action="{!loadPhoto}"/> <br/> <h1>3.Click the Done button to return to the previous page</h1> <p>(This will cancel an in-progress upload. )</p><br/> <apex:commandButton value="Done" action="{!savePhoto}"/>
</apex:pageBlock> </apex:form> </apex:page>
I don't know to call this in controller. Can u help for this?
I got some idea from this. After click the save button i have to redirect to my detail page of custom object and uploaded image will display on this page. Using page reference i can redirect to that detail page. Can you tell the steps?
Hi,
Try this with in form tag,
<apex:inputFile required="true" value="{!contentFile}" filename="{!nameFile}" />
Regards,
Rajesh.
<apex:page Controller="uploadPhoto" sidebar="false" showHeader="false">
<apex:form >
<apex:pageBlock title="Attach File" >
<h1>1.Select the File</h1>
<p>Type the path of the file or click the Browse button to find the file </p>
<apex:inputFile value="{!file}"/>
<br/>
<apex:commandButton value="Browse" action="{!loadPhoto}"/>
<br/>
<h1>2.Click the "Attach File" button.</h1>
<p>Repeat steps 1 and 2 to attach multiple files </p>
<p>(When the upload is completed the file information will appear below)</p><br/>
<apex:commandButton value="Attach File" action="{!loadPhoto}"/>
<br/>
<h1>3.Click the Done button to return to the previous page</h1>
<p>(This will cancel an in-progress upload. )</p><br/>
<apex:commandButton value="Done" action="{!savePhoto}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
I don't know to call this in controller. Can u help for this?
Thanks
Hi,
Try this,
public with sharing class FileUploadController {
public Document document {
get {
if (document == null)
document = new Document();
return document;
}
set;
}
public PageReference upload() {
document.AuthorId = UserInfo.getUserId();
document.FolderId = UserInfo.getUserId(); // put it in running user's folder
try {
insert document;
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));
return null;
} finally {
document.body = null; // clears the viewstate
document = new Document();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
return null;
}
}
<apex:page controller="FileUploadController">
<apex:sectionHeader title="Visualforce Example" subtitle="File Upload Example"/>
<apex:form enctype="multipart/form-data">
<apex:pageMessages />
<apex:pageBlock title="Upload a File">
<apex:pageBlockButtons >
<apex:commandButton action="{!upload}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection showHeader="false" columns="2" id="block1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="File Name" for="fileName"/>
<apex:inputText value="{!document.name}" id="fileName"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="File" for="file"/>
<apex:inputFile value="{!document.body}" filename="{!document.name}" id="file"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="description"/>
<apex:inputTextarea value="{!document.description}" id="description"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Keywords" for="keywords"/>
<apex:inputText value="{!document.keywords}" id="keywords"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Regards,
Rajesh.
I got some idea from this. After click the save button i have to redirect to my detail page of custom object and uploaded image will display on this page.
Using page reference i can redirect to that detail page. Can you tell the steps?
Hi,
add below code in save method and pass the object id instead of master.id.
PageReference ReturnPage = new PageReference('/' + Master.id);
ReturnPage.setRedirect(true);
return ReturnPage;
Regards,
Rajesh.
Without using <apex:inputFile> how can upload a file or image by clicking the "Browse" button.
Hi,
U need to use <apex:inputFile> tag and in upload u need to write the above code.
Regards,
Rajesh.
I need to attach image on my custom object. Using above code attachment stored in document object not in my custom object.
HI,
If u r directly storing the image from ur computer means u can have Rich Text data type for that field
or
Image can be store from documents means --
Please see below links
http://blog.shivanathd.com/2012/12/display-image-as-custom-field-on.html
http://suyati.com/display-an-image-as-a-custom-field-on-salesforce/
https://ap1.salesforce.com/help/doc/en/salesforce_useful_formula_fields.pdf
I have tested the above it's working fine.
Regards,
Rajesh.