Signing

Downloading a PAdES from SDS

805 views August 2, 2017 October 9, 2017 1

After creating a PAdES using the packaging service, the complete PAdES is available for download from the Session Data Storage.

[TestMethod]
public async Task How_to_download_a_document_from_SDS()
{
    string padesDocumentId = "300820131anomvdrt18vhkajyo1n00891l21i449i7tt5n2fqu911bkmh4";
    var httpClientHandler = new HttpClientHandler { Credentials = new NetworkCredential("demo", "Bond007") };

    using (var client = new HttpClient(httpClientHandler))
    {
        HttpResponseMessage response = await client.GetAsync("https://preprod.signicat.com/doc/demo/sds/" + padesDocumentId);
        byte[] pades = await response.Content.ReadAsByteArrayAsync();
        string filename = padesDocumentId + "_" + DateTime.Now.ToString("yyMMdd_HHmmss") +".pdf";
        File.WriteAllBytes(filename, pades);


        Console.WriteLine(Directory.GetCurrentDirectory() + "\\" + filename);
        Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        Assert.AreEqual("application/x-pades", response.Content.Headers.ContentType.ToString());
    }
}
package com.signicat.signature;

import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.junit.Test;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DownloadFromSds {
	// After creating a PAdES using the packaging service,
	// the complete PAdES is available
	// for download from the Session Data Storage.

	@Test
	public void how_to_download_a_document_from_SDS() throws Exception {
		String padesDocumentId = "1803201653g2jc3jn5kpq4pnyv4x866odr31771x26c5zr757vl00bjc8t";

		String filename = padesDocumentId + "_" + new SimpleDateFormat("yyMMdd_HHmmss").format(new Date()) + ".pdf";

		Executor.newInstance()
				.auth("demo", "Bond007")
				.execute(Request.Get("https://preprod.signicat.com/doc/demo/sds/" + padesDocumentId))
				.saveContent(new File(filename));
	}
}

Was this helpful?