You need to sign in to do that
Don't have an account?
Upload different formats of files into CONTENT VERSION - Library
*********VF Page***************
<apex:page controller="uploadFile">
<apex:messages />
<apex:form enctype="multipart/form-data" >
<apex:pageBlock title="Contribute Content" >
<apex:commandbutton action="{!upload}" value="Publish" status="status"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel > Title </apex:outputLabel>
<apex:inputTextarea value="{!title}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
title
<apex:inputFile value="{!file}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
*********Apex Class************
public class uploadFile {
public blob file { get; set; }
public String title{get;set;}
public ContentVersion cv { get; set; }
public PageReference upload() {
ContentVersion cv = new ContentVersion();
cv.versionData = file;
cv.title = title;
cv.pathOnClient ='/test img.jpeg';
cv.FirstPublishLocationId = '01dfr000000000gA'; //Change id
try
{
insert cv;
system.debug('*********************Result'+cv.pathonClient);
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading Document in Library'));
return null;
}
finally
{
cv= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Document uploaded successfully to library'));
return null;
}
}
My question Here is i could only upload jpeg files , and can see preview in library.
What if want to upload different formats of files...like pdf, csv, doc, txt jpeg, png etc....
Please help me wit this.. I would really appreciate for Quick response
Thanks
*********VF Page***************
<apex:page controller="uploadFile">
<apex:messages />
<apex:form enctype="multipart/form-data" >
<apex:pageBlock title="Contribute Content" >
<apex:commandbutton action="{!upload}" value="Publish" status="status"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel > Title </apex:outputLabel>
<apex:inputTextarea value="{!title}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
title
<apex:inputFile value="{!file}" fileName="{!fN}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
*********Apex Class************
public class uploadFile {
public String Type { get; set; }
public String fN { get; set; }
public blob file { get; set; }
public String title{get;set;}
public ContentVersion cv { get; set; }
public PageReference upload() {
ContentVersion cv = new ContentVersion();
cv.versionData = file;
cv.title = title;
//cv.versionData = EncodingUtil.Base64Decode(ConType);
cv.pathOnClient = fN;
cv.FirstPublishLocationId = '01dfr000000000gA'; //Change id
try
{
insert cv;
system.debug('*********************Result'+cv.pathonClient);
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading Document in Library'));
return null;
}
finally
{
cv= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Document uploaded successfully to library'));
return null;
}
}
All Answers
Tried this approach..
ContentVersion(
versionData = EncodingUtil.Base64Decode(base64BlobValue),
Title = fileName,
PathOnClient = '/'+fileName,
FirstPublishLocationId = libraryId);
http://salesforce.stackexchange.com/questions/733/isnt-contentversion-versiondata-updateable-amendable
*********VF Page***************
<apex:page controller="uploadFile">
<apex:messages />
<apex:form enctype="multipart/form-data" >
<apex:pageBlock title="Contribute Content" >
<apex:commandbutton action="{!upload}" value="Publish" status="status"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel > Title </apex:outputLabel>
<apex:inputTextarea value="{!title}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
title
<apex:inputFile value="{!file}" fileName="{!fN}" contentType="{!Type}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
*********Apex Class************
public class uploadFile {
public String Type { get; set; }
public String fN { get; set; }
public blob file { get; set; }
public String title{get;set;}
public ContentVersion cv { get; set; }
public PageReference upload() {
ContentVersion cv = new ContentVersion();
//cv.versionData = file;
cv.title = title;
cv.versionData = EncodingUtil.Base64Decode(ConType);
cv.pathOnClient = '/file';
cv.FirstPublishLocationId = '01dfr000000000gA'; //Change id
try
{
insert cv;
system.debug('*********************Result'+cv.pathonClient);
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading Document in Library'));
return null;
}
finally
{
cv= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Document uploaded successfully to library'));
return null;
}
}
Still Could not be able to insert all able to upload only few formats of files. still could not able to see preview in library..
Tried this link :
http://boards.developerforce.com/t5/Apex-Code-Development/Decode-Encode-Word-Documents-in-Apex/td-p/329545
*********VF Page***************
<apex:page controller="uploadFile">
<apex:messages />
<apex:form enctype="multipart/form-data" >
<apex:pageBlock title="Contribute Content" >
<apex:commandbutton action="{!upload}" value="Publish" status="status"/>
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel > Title </apex:outputLabel>
<apex:inputTextarea value="{!title}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
title
<apex:inputFile value="{!file}" fileName="{!fN}" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
*********Apex Class************
public class uploadFile {
public String Type { get; set; }
public String fN { get; set; }
public blob file { get; set; }
public String title{get;set;}
public ContentVersion cv { get; set; }
public PageReference upload() {
ContentVersion cv = new ContentVersion();
cv.versionData = file;
cv.title = title;
//cv.versionData = EncodingUtil.Base64Decode(ConType);
cv.pathOnClient = fN;
cv.FirstPublishLocationId = '01dfr000000000gA'; //Change id
try
{
insert cv;
system.debug('*********************Result'+cv.pathonClient);
}
catch (DMLException e)
{
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading Document in Library'));
return null;
}
finally
{
cv= new ContentVersion();
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Document uploaded successfully to library'));
return null;
}
}