Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Two things: </p> <p>For <strong>googleAccessId</strong> use:</p> <pre><code>String googleAccessId = service.getServiceAccountName(); </code></pre> <p>And for <strong>Signature</strong> use:</p> <pre><code>SigningResult signingResult = service .signForApp(stringToSign.getBytes()); String encodedSignature = new String(Base64.encodeBase64( signingResult.getSignature(), false), "UTF-8"); </code></pre> <p>That's what worked for me. See below a sample signer class:</p> <pre><code>public class GcsAppIdentityServiceUrlSigner { private static final int EXPIRATION_TIME = 5; private static final String BASE_URL = "https://storage.googleapis.com"; private static final String BUCKET = "my_bucket"; private static final String FOLDER = "folder"; private final AppIdentityService identityService = AppIdentityServiceFactory.getAppIdentityService(); public String getSignedUrl(final String httpVerb, final String fileName) throws Exception { final long expiration = expiration(); final String unsigned = stringToSign(expiration, fileName, httpVerb); final String signature = sign(unsigned); return new StringBuilder(BASE_URL).append("/") .append(BUCKET) .append("/") .append(FOLDER) .append("/") .append(fileName) .append("?GoogleAccessId=") .append(clientId()) .append("&amp;Expires=") .append(expiration) .append("&amp;Signature=") .append(URLEncoder.encode(signature, "UTF-8")).toString(); } private static long expiration() { final long unitMil = 1000l; final Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MINUTE, EXPIRATION_TIME); final long expiration = calendar.getTimeInMillis() / unitMil; return expiration; } private String stringToSign(final long expiration, String filename, String httpVerb) { final String contentType = ""; final String contentMD5 = ""; final String canonicalizedExtensionHeaders = ""; final String canonicalizedResource = "/" + BUCKET + "/" + FOLDER + "/" + filename; final String stringToSign = httpVerb + "\n" + contentMD5 + "\n" + contentType + "\n" + expiration + "\n" + canonicalizedExtensionHeaders + canonicalizedResource; return stringToSign; } protected String sign(final String stringToSign) throws UnsupportedEncodingException { final SigningResult signingResult = identityService .signForApp(stringToSign.getBytes()); final String encodedSignature = new String(Base64.encodeBase64( signingResult.getSignature(), false), "UTF-8"); return encodedSignature; } protected String clientId() { return identityService.getServiceAccountName(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload