+ Start a Discussion
Apex codingApex coding 

How to read a file on local machine using Apex

Hi
 
I have a requirement like reading a file on local mahine using Apex
after reading that file using Apex I want to send the contents of that file as an attachment through email
 
can any one send me the sample Apex code of reading a file on local machine
 
waitng for a quick reponse
 
regards
sunil
 
 
JonPJonP
Like all code running in the cloud, Apex code does not have access to your users' local file system.


Message Edited by JonP on 08-14-2008 10:07 AM
kriiyerkriiyer

Hey Sunil,

Hope this helps,

1) You would need to create a VisualForce page or SControl which would allow the user to select a file from the local machine.

2) Read the file through Javascript. There are functions avaiable.

3) You would need a Javascript code that would do a Base64encoding of the file contents and call an Apex function and pass the Base64encoded string. (This can be done using apex:actionFunction in VisualForce).  

4) In the Apex method you can create an Attachment object with the body attribute set to the Base64encoding of the file. Something like this

Attachment fileAttached = new Attachment();

fileAttached.Body = <base64encoded string>;

5) Insert the attachment object.

There is a way by which you can send it as an attachment by email. I'm not sure how to do it though.

Best Regards,

Krishnan

Rohan Shenoy 13Rohan Shenoy 13
What to do if the file size is too large and it causes timeout error. I also tried increasing the limit to 120 secs.
hims mosehims mose
Is this good idea to move the WordPress site for Saleforce service? I want to test the way on my WordPress blog machinescraft (https://machinescraft.com/).
Howard69Howard69
You would need to create a VisualForce page or SControl which would allow the user to select a file from the local machine. 2) Read the file through Javascript. There are functions avaiable.
MCDVOICE (https://www.mcdvoice.guru/)