Uploading and downloading large files

When you need to sign large files, you can create a requestSigning call without the application parameters and then upload the actual files separately for signing.

The upload URL and download URL are different for two factor enabled accounts and non-two factor accounts. See the tables below for URLs relevant to your account type.

URLs for two factor enabled environments

URLs for non-two factor environments

Uploading a large application file

After you create a signing set with requestSigning, request a large application file upload with a POST request to the Secure App Service portal.

Requesting a large application file upload

  1. Create your signing set.
    To create your signing set use requestSigning but omit the application parameter.
  2. Send your upload request.
    1. Send an upload request using the POST method to the upload URL relevant to your environment.
    2. The request body must include the following information:
      • Signing set ID (returned in the requestSigning response)
      • Partner code
      • The application file to be signed in binary format as a multipart form-data encoded POST parameter.
      • Username and password
      • Flag for directory signing
  3. Upload the files.
    When you upload the files, make sure your .zip file meets the following prerequisites:
    1. The .zip file must include all of the files listed in commaDelimitedFileNames, as specified in the SOAP request. Do not include any additional files.
    2. The size of the zip file cannot exceed 1.95 GB
    3. The total size of all the files (uncompressed) cannot exceed 1.95 GB.

Signing and file uploading

  • The time required for code signing varies depending on several factors (for example, the load on the server when the signing is requested).
  • When the upload succeeds, the call returns a success message. When an upload fails, the call returns an error code, fieldname, and message.
    The upload operation does not wait for the signing process to complete to return the response.
  • The file upload service processes data streams conforming to the MIME multipart format as defined in RFC 1867.
    Arbitrarily large amounts of data in the stream can be processed under constant memory usage. Secure App Service does not support nested streams (multipart data entities in body data).

Verifying that the files have been signed

To verify that the files are signed, perform one of the following tasks:

  • Use getSigningSetDetails with returnApplication set to false.
    This setting returns the signing set status.
  • Send a request to download the application files.
    Download is only allowed if the signing set is signed.
HTML from upload
<html>

<head>
<title>Upload Application File</title>
</head>

<body>

<form action="https://api.pki.digicert.com/webtrust/SASUploadApplication" 
enctype="multipart/form-data" method="post">

<p>
Please specify an application file:
<input type="file" id="application" name="application" size="50" />
<br/>
Username
<input type="text" id="username" name="username" size="50" />
<br/>
Password
<input type="text" id="password" name="password" size="50" />
<br/>
Signing Set ID
<input type="text" id="signingsetid" name="signingsetid" size="50" />
<br/>
Partner Code
<input type="text" id="partnerCode" name="partnerCode" size="50" />
<br/>
IsDirectorySigning
<input type="text" id="isdirectorySigning" name="isdirectorySigning" size="50" />
</p>

<div>
  <input type="submit" value="UploadFile" />
</div>

</form>

</body>
</html>
Java
import org.apache.http.HttpEntity;
import org.apache.http.HttpVersion;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import java.io.File;
import java.util.Calendar;
import java.util.Date;


public class UploadClient {

    public static void upload(String signingSetId, String username, 
      String password, String partnerCode, File file, String URL) {
        try {
            
            //add your client certificate
            System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
            System.setProperty("javax.net.ssl.keyStore", "C:\\\\Program Files\\\\Java\\\\jdk1.8.0_25\\\\bin\\\\sas_keystore.p12");
            System.setProperty("javax.net.ssl.keyStorePassword", "yourPassword");

            Calendar calendar = Calendar.getInstance();
            System.out.println("Upload Started for File: " + file.getName() 
              + ", Size: "+ file.length());
            long startTime = new Date().getTime();
            System.out.println(startTime);
            String urlString = URL;
            CloseableHttpClient client = HttpClientBuilder.create().build();

            //CloseableHttpClient client = 
            //  HttpClients.custom().useSystemProperties().build();
            HttpClientContext context = HttpClientContext.create();
            context.setAttribute("http.protocol.version", 
              HttpVersion.HTTP_1_1);
            HttpPost post = new HttpPost(urlString);
            MultipartEntityBuilder builder = 
              MultipartEntityBuilder.create();
            builder.setMode(HttpMultipartMode.STRICT);
            FileBody fileBody = new FileBody(file);
            builder.addPart("application", fileBody);
            builder.addTextBody("username", username);
            builder.addTextBody("password", password);
            builder.addTextBody("signingsetid", signingSetId);
            builder.addTextBody("partnerCode", partnerCode);
            HttpEntity entity = builder.build();
            System.out.println("Uploading file...");
            post.setEntity(entity);
            String response = 
              EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
            client.close();
            long endTime = new Date().getTime();
            System.out.println(endTime);
            System.out.println("Total Time Taken: " + (endTime-startTime));
            System.out.println("Done: " + response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Downloading a large application file

After upload and signing, you can send a request to download any application or supporting files that have been uploaded against the signing set.To download a large application file, send a POST request to the download URL relevant to your environment.

The request body must include the following information:

  • The signing set ID and partner code
  • At least one download option (downloadApplicationFiles or downloadSupportingFiles)
  • Your username and password.

You can download application files only if the signing set is signed. If you request download for application files for any state other than signed, an error is returned.

To use this feature, your code should poll for the availability of the signed file. Use getSigningSetsDetails with the application indicator, the returnApplication element, set to false.

Depending on the signing set state and the type of the files requested for download, the files are downloaded or an error occurs. See the File download scenarios table below for the possible scenarios:

File download scenarios

Signing set status

downloadApplicationFiles

downloadSupportingFiles

Result

Signed

True

True

All signed application files and all supporting files are downloaded.

Signed

True

False

All signed application files are downloaded.

Signed

False

True

All supporting files are downloaded.

Any state besides Signed

True

True

Error stating that files cannot be downloaded

Any state besides Signed

True

False

Error stating that files cannot be downloaded

Any state besides Signed

False

True

All supporting files are downloaded.

HTML form download
<html>

<head>
<title>Download Application File</title>
</head>

<body>

<form action="https://api.pki.digicert.com/webtrust/SASDownloadApplication" 
enctype="multipart/form-data" method="post">

<p>
Username
<input type="text" id="username" name="username" size="50" />
<br/>
Password
<input type="text" id="password" name="password" size="50" />
<br/>
Signing Set ID
<input type="text" id="signingsetid" name="signingsetid" size="50" />
<br/>
Partner Code
<input type="text" id="partnerCode" name="partnerCode" size="50" />
<br/>
Download Application Files
<input type="text" id="downloadApplicationFiles" name="downloadApplicationFiles" size="50" />
<br/>
Download Supporting Files
<input type="text" id="downloadSupportingFiles" name="downloadSupportingFiles" size="50" />
</p>

<div>
  <input type="submit" value="Download" />
</div>

</form>

</body>
</html>
Java
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Calendar;
import java.util.Date;
import java.util.UUID;

public class DownloadClient {



    public static void downloadNew(String signingSetId, String username, 
        String password, String partnerCode, String URL) 
        throws URISyntaxException, IOException {
        // Engage the HTTP client

        System.out.println("Download Started ");
        Calendar calendar = Calendar.getInstance();
        long startTime = new Date().getTime();
        //System.out.println(startTime);
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(URL);
        httpPost.setHeader("enctype", "multipart/form-data");

        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
        builder.addTextBody("username", username);
        builder.addTextBody("password", password);
        builder.addTextBody("signingsetid", signingSetId );
        builder.addTextBody("partnerCode", partnerCode);
        builder.addTextBody("downloadApplicationFiles", "true");
        builder.addTextBody("downloadSupportingFiles", "true");
        httpPost.setEntity(builder.build());
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            InputStream inputStream = entity.getContent();
            writeStreamToFile(inputStream, "download.zip");
        }
        long endTime = new Date().getTime();
        //System.out.println(endTime);
        System.out.println("Total Time Taken: " + (endTime-startTime));
        System.out.println("Operation Completed");
    }


    public static File writeStreamToFile(InputStream in, String fileName) {
        String tmpFilePrefix = "tmp_";
        String tmpFileSuffix = "zipEntry";
        File tmpDir = null;

        File zipFile = null;
        BufferedOutputStream bos = null;

        try {
            if (fileName != null) {
                File f = new File(fileName);
                File parent = f.getParentFile();
                if (parent != null) {
                    tmpDir = new File("D:\\\\download", parent.getPath());

                } else {
                    tmpDir = new File("D:\\\\download");
                }
                tmpFileSuffix = f.getName();
            }

            zipFile = File.createTempFile(tmpFilePrefix + UUID.randomUUID(),
              tmpFileSuffix, tmpDir);
            //zipFile.deleteOnExit();


            bos = new BufferedOutputStream(new FileOutputStream(zipFile));
            byte[] buf = new byte[1024];
            int len;
            // Copy bytes from the input stream to the new zip file.
            while ((len = in.read(buf)) >= 0) {
                bos.write(buf, 0, len);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bos != null) {
                try {
                    bos.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            try {
                if (in != null) in.close();
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
        }
        return zipFile;
    }
}

We use cookies to ensure that we give you the best experience on our website. By using this site, you agree to the Terms of Service.