You need to sign in to do that
Don't have an account?
Pass a default path for <apex:inputFile> tag in attachment Upload
Hi,
I want to pass a default path value for the inputFile tag in uploading an attachment to the record. By default it opens the documents folder but how can I customize the location where it looks for the uploading document by default.
I am using the following code to upload the document
<apex:page controller="AttachmentUploadController">
<apex:form >
<apex:outputText value="Parent Object ID: "/><apex:inputText value="{!parentId}"/><br/>
<apex:outputText value="Input File: "/><apex:inputFile value="{!attach.body}" filename="{!attach.name}" /><br/>
<apex:commandButton value="Upload" action="{!upload}"/>
</apex:form>
</apex:page>
Controller
public with sharing class AttachmentUploadController
{
public String parentId {get;set;}
public Attachment attach {get;set;}
public AttachmentUploadController()
{
attach = new Attachment();
}
public ApexPages.Pagereference upload()
{
attach.ParentId = parentId;
insert attach;
return new ApexPages.Standardcontroller(attach).view();
}
}
when I click on browse it opens the c drive while I want it to be opened in d: by default
Also is it possible that we can define a file name which is automatically uploaded from the location on any event or time based trigger??
Any ideas how can I achieve the same?
Thanks in advance,
Aakash
Hi Akash,
Yes you can use controller But some point you need to consider
1. Visualforce page will not allow cache more than 128 KB so when you select file it will be more than 128 K it will give the error.
2. SFDC allow attachment by UI with 5 or 10 MB which will not allow in visualforce.
Solution - Store attachment in document object.
http://www.linkedin.com/groups/Upload-file-as-Attachment-record-4385029.S.130855271
In your upload method you need to add the below points
get the respective folder id by using a query ....and you need to create a document object record to store in the respective folder..
folder obj = [select id from folder where name = 'x'];
document obj = new document();
obj.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents some thing like this ....
insert obj;
https://developer.salesforce.com/forums/ForumsMain?id=906F000000098MpIAI
= 'any other id you want here'; // Fetch Id dynamically by using [Select Id from Folder where Name='My Images'].*/
http://www.mindfiresolutions.com/Uploading-a-Document-into-Salesforce-using-Visualforce-Page-1593.php
public FileUploadController(){
folderList = [SELECT Id,Name FROM Folder WHERE Name = 'IMAGE DOCS' ];
if(folderList!=null && !folderList.isEmpty()){
Folder folder = folderList.get(0);
documentList = [SELECT Name , Type , Url, AuthorId, Body ,
LastReferencedDate , LastViewedDate, FolderId FROM Document
document where FolderId IN:folderList ];
}
http://salesforce.stackexchange.com/questions/16837/apexinputfile-cant-be-used-in-conjunction-with-an-action-component-when-im-tr
Or try these links below,
= 'any other id you want here'; // Fetch Id dynamically by using [Select Id from Folder where Name='My Images'].*/
http://www.mindfiresolutions.com/Uploading-a-Document-into-Salesforce-using-Visualforce-Page-1593.php
public FileUploadController(){
folderList = [SELECT Id,Name FROM Folder WHERE Name = 'IMAGE DOCS' ];
if(folderList!=null && !folderList.isEmpty()){
Folder folder = folderList.get(0);
documentList = [SELECT Name , Type , Url, AuthorId, Body ,
LastReferencedDate , LastViewedDate, FolderId FROM Document
document where FolderId IN:folderList ];
}
http://salesforce.stackexchange.com/questions/16837/apexinputfile-cant-be-used-in-conjunction-with-an-action-component-when-im-tr
Regards,
Ashish