@scloud/lambda-fileupload
Version:
Functions uploading/downloading files with Lambda/API Gateway where the file size is greater than the payload limit.
34 lines (33 loc) • 2.47 kB
TypeScript
/**
* Ensures no leading or training slashes
*/
export declare function tidy(path: string): string;
/**
* Generates a pre-signed url for a GET request to the specified bucket and key. This is useful for downloading a file from S3 programmatically.
* This allows you to download files via API Gateway & Lambda where there's a request payload size limit of 10MB & 6MB.
* This is particularly useful for, say, a mobile app, as it allows the app to download a file using a url generated by its backend without needing to hold AWS credentials locally on the device.
* @param expires (optional) The number of seconds until the presigned url expires, defaults to 600 (1 minute) to allow for latency plus clock drift.
* @returns The signed url as a string
*/
export declare function getUrl(bucket: string, key: string, expiresIn?: number): Promise<string>;
/**
* Generates a pre-signed url for a PUT request to the specified bucket and key. This is useful for uploading a file to S3 programmatically.
* This allows you to upload files via API Gateway & Lambda where there's a request payload size limit of 10MB & 6MB.
* This is particularly useful for, say, a mobile app, as it allows the app to upload a file using a url generated by its backend without needing to hold AWS credentials locally on the device.
* @param expires (optional) The number of seconds until the presigned url expires, defaults to 600 (1 minute) to allow for latency plus clock drift.
* @returns The signed url as a string
*/
export declare function putUrl(bucket: string, key: string, expiresIn?: number): Promise<string>;
/**
* Generates pre-signed POST details suitable for use e.g. on a form on a web page to upload a file to S3.
* See: https://www.npmjs.com/package/@aws-sdk/s3-presigned-post
* @param bucket The bucket to upload to
* @param key The key to upload to
* @param expires (optional) The number of seconds until the presigned post expires, defaults to 3600 (1 hour) to give a user time to submit the form
* @param maxSize (optional) The maximum size of the file to allow for upload, defaults to 100M
* @returns A form action url and (hidden) field values for the upload form. For documentation see: https://www.npmjs.com/package/@aws-sdk/s3-presigned-post#user-content-post-file-using-html-form
*/
export declare function postUrl(bucket: string, key: string, expires?: number, maxSize?: number): Promise<{
url: string;
fields: Record<string, string>;
}>;