+ Start a Discussion
SimplySfdcSimplySfdc 

download attachment

Hi, I would like to download attachment from sforce.com, a link to the file is enough. I have to point to https://emea.salesforce.com/{attachment_id} example: https://emea.salesforce.com/00P20000000ivZfEAI and the page just bring me to sforce.com file attachment. Any feedback would be very apprciated.

Thanks.
sq

DevAngelDevAngel

Hi sq,

What is your question?

SimplySfdcSimplySfdc

The link to the attachment detail page looks like this:
https://na1-api.salesforce.com/00P30000000kDCz
If you put your mouse over the "Click here to view this file" link you will see a url like this:
https://na1-api.salesforce.com/servlet/servlet.FileDownload?file=00P30000000kDCz
This is the direct link to download the attachment.

If I develop an aspx page, after make a successful logon through sforce API, can I get this file without have to open salesforce.com?

second, is the prefix is always https://na1-api.salesforce.com/ or I can the the URL from somewhere in API ?

Thanks.
sq

 

 

SimplySfdcSimplySfdc

Hi, can somebody here can answer my question? thanks.

sq

DevAngelDevAngel

Hi sq,

So, the second url will get the file directly, assuming that all the proper authentication information is also included in the request (session id for instance).  If you are using a url, you will need to obtain a session id and place it in a cookie (sid=qewrqklwjerioqwer).

The prefix is not always na1-api.  It is org dependent.  When logging in via the api you will get a url with the correct prefix back and actually, in the app in the address or the link hover you should be seeing na1.salesforce.com.  Another way to determine the url authority is to make a describe call to user or some other standard or custom object.  There are 3 fields that have the url pattern for the object described in which the correct authority is indicated.

GlennWGlennW
SQ;

Why don't you just access the attachment object via the API and read the base64 encoded body and the name of the file. Then, in ASPX, just decode the base64 string and save the file stream to a browsable location on your server?

GlennW
SimplySfdcSimplySfdc

Hi Glenn,

Yes, this is the solution I would like to implement, and I am using aspx also. Do you have sample of code for this solution please....  thanks

FYI: I can do upload file to sforce through API using base64 encoded also.

regards,
sq

 

SimplySfdcSimplySfdc

Hi,

thanks everybody for the solution of using base64 encoded, do anybody here have sample of code for this solution please....  thanks

FYI: I can do upload file to sforce through API using base64 encoded also.

regards,
sq