OLE Data Extraction from Specific Drawing Object at Amazon S3 Storage

saaspose

New member
Joined
Jan 15, 2013
Messages
3
Points
0
This technical tip allows developers to extract ole data from a specific drawing object using Saaspose.Words REST API in your .NET applications. You need to upload file to Amazon S3 storage before running this example. Some important steps for performing this task are to specify product URI, Choose from jpeg, tiff, png and bmp, build URI, sign URI, get response stream, required methods and classes are also given in detail. Please check Saaspose example section for more details on how to upload files to Amazon S3 storage.

Sample Code for Extracting Ole Data from a Drawing Object at Amazon S3 Storage
Code:
SaasposeApp.AppKey = "9a******************";
            SaasposeApp.AppSID = "77*********************";
            //specify product URI
            Product.BaseProductUri = @"api*saaspose*com/v1.0";
            try
            {
                int drawingObjectIndex = 1;
                string fileName = "SampleDrawingObject.doc";
                string saveFormat = "xls"; //Choose from jpeg, tiff, png and bmp
                string outputFile = "C:\\OutputDrawingObject." + saveFormat;
                string amazonS3StorageName = "MyAmazonS3Storage";
                string amazonS3BucketName = "MyS3Bucket"; // include folder name if file is not at root folder 

                //build URI
                string strURI = Product.BaseProductUri + "/words/" + fileName + "/drawingObjects/" + drawingObjectIndex;
                strURI += "/oleData?storage=" + amazonS3StorageName + "&folder=" + amazonS3BucketName;

                //sign URI
                string signedURI = Sign(strURI);

                //get response stream
                Stream responseStream = ProcessCommand(signedURI, "GET");

                using (Stream fileStream = System.IO.File.OpenWrite(outputFile))
                {
                    CopyStream(responseStream, fileStream);
                }
                responseStream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            } 

//Following are the required methods and classes 

        public static string Sign(string url)
        {
            try
            {
                // Add appSID parameter.
                UriBuilder builder = new UriBuilder(url);
                if (builder.Query != null && builder.Query.Length > 1)
                    builder.Query = builder.Query.Substring(1) + "&appSID=" + SaasposeApp.AppSID;
                else
                    builder.Query = "appSID=" + SaasposeApp.AppSID;
                // Remove final slash here as it can be added automatically.
                builder.Path = builder.Path.TrimEnd('/');
                // Compute the hash.

                byte[] privateKey = System.Text.Encoding.UTF8.GetBytes(SaasposeApp.AppKey);

                System.Security.Cryptography.HMACSHA1 algorithm = new System.Security.Cryptography.HMACSHA1(privateKey);
                //System.Text.ASCIIEncoding
                byte[] sequence = System.Text.ASCIIEncoding.ASCII.GetBytes(builder.Uri.AbsoluteUri);
                byte[] hash = algorithm.ComputeHash(sequence);
                string signature = Convert.ToBase64String(hash);
                // Remove invalid symbols.
                signature = signature.TrimEnd('=');
                signature = System.Web.HttpUtility.UrlEncode(signature);
                // Convert codes to upper case as they can be updated automatically.
                signature = System.Text.RegularExpressions.Regex.Replace(signature, "%[0-9a-f]{2}", e => e.Value.ToUpper());

                // Add the signature to query string.
                return string.Format("{0}&signature={1}", builder.Uri.AbsoluteUri, signature);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        public static Stream ProcessCommand(string strURI, string strHttpCommand)
        {
            try
            {
                Uri address = new Uri(strURI);
                System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(address);
                request.Method = strHttpCommand;
                request.ContentType = "application/json";
                request.ContentLength = 0;
                System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
                return response.GetResponseStream();
            }
            catch (System.Net.WebException webex)
            {
                throw new Exception(webex.Message);
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }
        }

        public static void CopyStream(Stream input, Stream output)
        {
            try
            {
                byte[] buffer = new byte[8 * 1024];
                int len;
                while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
                {
                    output.Write(buffer, 0, len);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
    }


    public class Product
    {
public static string BaseProductUri { get; set; }
    }
    public class SaasposeApp
    {
public static string AppSID { get; set; }
public static string AppKey { get; set; }
    }
 
Older threads
Replies
1
Views
2,849
Replies
4
Views
3,903
Replies
5
Views
4,300
Replies
13
Views
5,264
Newer threads
Replies
10
Views
10,531
Replies
3
Views
4,119
Replies
25
Views
20,074
Replies
1
Views
2,977
Latest threads
Replies
1
Views
270
Replies
1
Views
209
Replies
2
Views
529
Replies
4
Views
1,073
Recommended threads
Replies
0
Views
2,999
Replies
45
Views
22,035
Replies
34
Views
35,026
Similar threads
Replies
6
Views
3,855
Replies
2
Views
3,779
Replies
1
Views
1,957
Replies
1
Views
5,138

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top