1

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

  • Since it works in another sandbox, my guess is that your URL does not contain the correct sandbox instance. Double check if your current sandbox is also on cs18 instance. – Aayush K Sep 21 '15 at 15:36
  • Yes i did change that one. The original one was on the instance cs17. The strange things is the image can be found on either one. – user24818 Sep 21 '15 at 15:44
  • i just saw the image tag didn't get copied right here is the code <img alt="cats" src="c.cs18.content.force.com/…> – user24818 Sep 21 '15 at 15:49
  • have you tried with hardcoded url instead of dynamic one? – Himanshu Sep 21 '15 at 17:08
  • Yes i have tried that as well – user24818 Sep 21 '15 at 17:43
1

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

  • That did not fix it but you got me to look in the right place. I didn't add the mime type and the extension has a . there too. , i'll post the working code once it get it together. thanks a ton!!! – user24818 Sep 21 '15 at 18:35
0

Thanks to @Himanshu . He got me looking in the right place. I found that the file did not have the correct mime type and the file extention was not being recognized as a jpeg. I changed Type = fileInfo.Extension, to Type = fileInfo.Extension.Remove(0,1),

And the whole thing works.

the final working code to upload a public document with the soap api is

 FileInfo fileInfo = new FileInfo(memberImageFiles.FullImageFilePath);
                    byte[] data = File.ReadAllBytes(memberImageFiles.FullImageFilePath);

                    //use the file info to populate the SF document object
                    Document document = new Document
                    {
                        Name = fileInfo.Name,
                        IsPublic = true,
                        FolderId = folderId,
                        Description = " upload of file " + memberImageFiles.ImageName,
                        Body = data,
                        Type = fileInfo.Extension.Remove(0,1),
                        IsPublicSpecified = true
                    };

                    SaveResult[] result = factory.SfSoapFactory.create(new sObject[] {document});

here is the dynamic url that is created for viewing the image. todo abstract the server url.

                            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>";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.