Skip to content

What This Adds In Cloud Code

  • Pre-signed read/upload URLs for S3-compatible storage.
  • Optional site-storage mode without passing credentials.
  • Secure key sanitization and expiry validation.

Quick Start

js
const S3 = require('s3');
const s3 = new S3();
const uploadUrl = s3.generateUploadUrl('uploads/avatar.png', { contentType: 'image/png' });

API

FunctionParamsReturnsNotes
new S3(options?)optional credentials configS3ClientWrapperEmpty options uses site storage integration.
generateGetUrl(key, options?)key: string, optionsstringSigned GET URL.
generateUploadUrl(key, options?)key: string, optionsstringSigned PUT upload URL.
generatePostForm(key, options?)key: string, options{ url, fields }Browser POST upload helper payload.

Custom mode requires bucket and credentials.access_key_id + credentials.secret_access_key.

Practical Example

js
const S3 = require('s3');

const s3 = new S3();
const signed = s3.generateGetUrl(`exports/${request.params.file_name}`, { expires_in: 3600 });

response.success({ download_url: signed });

Failure Modes & Gotchas

  • Missing key or invalid bucket/expiry raises errors.
  • Use expires_in (snake case). Max is one week (604800).
  • Runtime sanitizes key path (for example removes traversal patterns).