[SalesForce] How to make an image publicly accessible

I wanted to store contacts profile pictures in the public folder and use the public check box to make them viewable on a wordpress website but the images always ask for a login to view.
Here is a screen shot of the uploaded file from the soap api.
/servlet.ImageServer?id=01511000000cmPQAAY&oid=00D1enter image description here

the api code is as such

FileInfo fileInfo = new FileInfo(memberImageFiles.FullImageFilePath);
byte[] data = File.ReadAllBytes(memberImageFiles.FullImageFilePath);
Document document = new Document{
    Name = fileInfo.Name,
    IsPublic = true,
    FolderId = folderId,
    Description = " upload of file " + memberImageFiles.ImageName,
    Body = data,
    Type = fileInfo.Extension,
    IsPublicSpecified = true
};
var curentUser = sfdcBinding.getUserInfo();
SaveResult[] result = sfdcBinding.create( new sObject[] { document });
Contact user = (Contact) getUserIdResult.records[0];
user.Main_Profile_Picture__c = "<img alt=\"" + fileInfo.Name + "\" src=\"https://c.cs18.content.force.com/servlet/servlet.ImageServer?id=" + result[0].id + "&oid=" + curentUser.organizationId + "\"></img>";

here is the image tag that it produces

https://c.cs18.content.force.com/servlet/servlet.ImageServer?id=01511000000cmPQAAY&oid=00D1100000C1nc6EAB

It it the last line. I ported this over from php and it worked in another sandbox but for some reason it doesn't work in this sandbox. Any help would be greatly appreciated.
Thanks
Pk

Best Answer

Can you try with following steps

  1. Right click and copy Image URL
  2. Open incoginto mode and try to hit url.
  3. if you see that image in incoginto mode try to use that url in your code.

Copy Image url

Related Topic