Quantcast
Channel: PDCM's Activities
Viewing all articles
Browse latest Browse all 170

Getting PDF file from Blob Storage: Error Failed to Open Document

$
0
0

Hi All,

I need help on this one. I'm getting the PDF file from Blob Storage the re-upload it to another record as Annotation (Notes). But when I tried to open the document, it prompts me "Failed to Open Document". I can successfully open a text file, an excel file or other documents except for PDF. Here's my code:

using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, uri)
            { Content = (requestPayload == null) ? null : new ByteArrayContent(requestPayload) })
            {
                using (var client = new HttpClient())
                {
                    var response = client.SendAsync(httpRequestMessage).Result;
                    if (response.IsSuccessStatusCode)
                    {
                        tracer.Trace(String.Format(blobType));
                        if (blobType == "application/pdf")
                        {
                            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
                        }

                        string data = response.Content.ReadAsStringAsync().Result;
                        tracer.Trace(String.Format(response.Content.Headers.ContentType.ToString()));
                        
                        byte[] byteData = System.Text.Encoding.UTF8.GetBytes(data);
                        string encoded = Convert.ToBase64String(byteData, 0, System.Text.Encoding.UTF8.GetByteCount(data));
                        return encoded;
                    }
                }
            }



Viewing all articles
Browse latest Browse all 170

Trending Articles