• barak inbal 10
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
I have C# batch which communicate with salesforce objects via SOAP API.
I want to fetch an image which is part of the Rich Text Field in salesforce custom object.
The rich text field himself is Html text and I can get the url of the image tag, but the problem is that the url himself is Https = Http secure connection:
The url of the image tag:

 https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I (http://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I)

As a result of this, I can't get the resource and write it to a file as a local image for later use.
This is the C# code for fetching the image:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    bool answer = response.ContentType.StartsWith("image", StringComparison.OrdinalIgnoreCase);
     if ((response.StatusCode == HttpStatusCode.OK ||
                        response.StatusCode == HttpStatusCode.Moved ||
                        response.StatusCode == HttpStatusCode.Redirect)&&
                        response.ContentType.StartsWith("text/html", StringComparison.OrdinalIgnoreCase)){
       // if the remote file was found, download it
         using (Stream inputStream = response.GetResponseStream())
         using (Stream outputStream = File.OpenWrite(filepath))
                        {
                            byte[] buffer = new byte[8192];
                            int bytesRead;
   
                            logger.InfoFormat("Writing to file, filepath:{0}", filepath);
                            do
                            {
                                bytesRead = inputStream.Read(buffer, 0, buffer.Length);
                                logger.InfoFormat("bytesRead: {0} ", bytesRead);
                                outputStream.Write(buffer, 0, bytesRead);
                            } while (bytesRead != 0);
                            //TODO outputStream.Close();
   
                        }
                        return true;
   
                    }
                }
                catch (Exception ex)
                {
                    logger.ErrorFormat("Failed to download {0} to {1} : {2}",
                        uri, filepath, ex.Message);
                    logger.Debug("Failed to download " + uri, ex);
                }
   
                return false;



I know that the secure url using java servlet for exposing the image to the world.
The problem is that I can't get the image data and always get the following respond:

    
<script>
    if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I'); }  else
    if (window.location.replace){
    window.location.replace('https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I');
    } else {;
    window.location.href ='https://ngam--kerensen.cs17.my.salesforce.com?ec=302&startURL=%2Fcontent%2Fsession%3Furl%3Dhttps%253A%252F%252Fngam--kerensen--c.cs17.content.force.com%252Fservlet%252FrtaImage%253Feid%253Da1Vg0000000lTkK%2526feoid%253D00N20000003jcie%2526refid%253D0EMg00000009N4I';
    }
    </script>



Any suggestion how to get the actual image data from the Rich Text Area field?

We have a  C# batch process which communicate with Salesforce DB salesforce through C# SOAP API.
Recently some of the fields which are rmotely querying, have change their type from Text type to Rich text area.
As a result of this , the body request is now larger , and can include items like pictures or external attachments.
As a result of this, we are getting alots of timeouts from server side. 

1. What can be the cause of this timeouts? any restrication on the size of body request in C# soap api?
2. What is the right technique to handle this problem.