How to load and render AWS S3 files using Group Docs in .Net(Framework 4.8)

How to load and render AWS S3 files using Group Docs in .Net(Framework 4.8)

@bajirao.shinde

You can use AWSSDK package to load a file from S3 with GetObject method. The code snippet can be found in Load document from Amazon S3 Storage documentation article. Here is the code:

string key = "sample.docx";
Stream stream = DownloadFile(key);

using (Viewer viewer = new Viewer(stream))
{
    HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();                
    viewer.View(viewOptions);
}

static Stream DownloadFile(string key)
{
    AmazonS3Client client = new AmazonS3Client();
    string bucketName = "my-bucket";
    GetObjectRequest request = new GetObjectRequest
    {
        Key = key,
        BucketName = bucketName
    };
    using (GetObjectResponse response = client.GetObject(request))
    {
        MemoryStream stream = new MemoryStream();
        response.ResponseStream.CopyTo(stream);
        stream.Position = 0;
        return stream;
    }
}

Please let us know if you have any issues with rendering files from S3.

Thank you for your email Vladimir!

What if the object is not public? Can you please help us knowing this.

image001.png (1.76 KB)

image002.png (17.9 KB)

@bajirao.shinde

According to GetObject’s method description you should have read access rights to retrieve an object:

You must have READ access to the object.