Returns a set of signed HTTP headers you can use to make an authenticated request directly to the storage bucket (S3/GCS) for a given file — for example, to fetch the file's bytes yourself, or confirm it exists, without generating a signed download URL first.
This is an optional, supporting piece of the upload/download process — most integrations won't need it unless they're making their own direct HTTP calls to storage. See Uploading a file end-to-end for where this could fit in.
How to call this method
global static Map<String,String> getAmazonHeaders(String item)
global static Map<String,String> getAmazonHeaders(String item, String versionId)
Parameters
|
Parameter |
Type |
Required |
Description |
|---|---|---|---|
|
|
|
Yes |
The storage key of the object — this is the file record's |
|
|
|
No |
A specific version's Id, if the file lives in a version-enabled bucket and you want headers for that version rather than the current one. |
Return value
Returns a Map<String,String> of HTTP header names to values — a signed (Version 4) request — that you attach to your own HttpRequest when calling the storage endpoint directly.
Notes
-
This method figures out which bucket the file lives in by matching
itemagainst existing file records with that key. If more than one record shares the key (which happens mid-new-version-upload), it resolves to the bucket used for new-version uploads. -
This doesn't make the HTTP request for you — you still build and send the
HttpRequestyourself using these headers.
Example
String storageKey = '500XX000001abcAAA/069XX0000004Cx1AAE/invoice.pdf';
Map<String,String> headers = SDriveTools.getAmazonHeaders(storageKey);
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:S3_Named_Credential/' + storageKey); // or your bucket's full URL
req.setMethod('GET');
for (String key : headers.keySet()) {
req.setHeader(key, headers.get(key));
}
Http http = new Http();
HttpResponse res = http.send(req);
System.debug('Status: ' + res.getStatusCode());