Edits history of script submission #9901 for ' Generate signed URL (s3)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
    import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
    import { S3Object } from 'windmill-client';
    
    // Define the S3 resource type
    type S3 = {
      port: number,
      bucket: string,
      region: string,
      useSSL: boolean,
      endPoint: string,
      accessKey: string,
      pathStyle: boolean,
      secretKey: string
    }
    
    /*
    * * Generates a presigned URL for accessing an S3 object
    * @param {S3Object} file - The uploaded file
    * @param {S3} s3Resource - The S3 resource configuration
    * @param {number} expiresIn - The time that the link is valid. Maximum is 604800 seconds (7 days)
    * @returns Promise<string> - The presigned URL
    */
    export async function main(file: S3Object, s3Resource: S3, expiresIn: number) {
      // Use the S3 resource to get credentials and configuration
      const bucketName = s3Resource.bucket; // Use the bucket from the S3 resource
      const region = s3Resource.region; // Use the region from the S3 resource
    
      const protocol = s3Resource.useSSL ? 'https' : 'http';
      const endpoint = `${protocol}://${s3Resource.endPoint}${s3Resource.port ? ':' + s3Resource.port : ''}`;
    
      // Initialize S3 client with credentials from the S3 resource
      const s3Client = new S3Client({
        region,
        endpoint,
        forcePathStyle: s3Resource.pathStyle,
        credentials: {
          accessKeyId: s3Resource.accessKey, // Use access key from the S3 resource
          secretAccessKey: s3Resource.secretKey, // Use secret key from the S3 resource
        },
      });
    
      if (typeof file === 'string') {
        throw new Error("This script does not support S3Object in string format")
      }
    
      const getCommand = new GetObjectCommand({
        Bucket: bucketName,
        Key: file.s3, // Use the key from the S3Object parameter
      });
    
      const presignedUrl = await getSignedUrl(s3Client, getCommand, { expiresIn });
    
      return presignedUrl;
    
    }

    Submitted by hugo989 176 days ago

  • bun
    import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
    import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
    import { S3Object } from 'windmill-client';
    
    // Define the S3 resource type
    type S3 = {
      port: number,
      bucket: string,
      region: string,
      useSSL: boolean,
      endPoint: string,
      accessKey: string,
      pathStyle: boolean,
      secretKey: string
    }
    
    /*
    * * Generates a presigned URL for accessing an S3 object
    * @param {S3Object} file - The uploaded file
    * @param {S3} s3Resource - The S3 resource configuration
    * @param {number} expiretime - The time that the link is valid. Maximum is 604800 seconds (7 days)
    * @returns Promise<string> - The presigned URL
    */
    export async function main(file: S3Object, s3Resource: S3, expiretime: number) {
      // Use the S3 resource to get credentials and configuration
      const bucketName = s3Resource.bucket; // Use the bucket from the S3 resource
      const region = s3Resource.region; // Use the region from the S3 resource
    
    
      // Initialize S3 client with credentials from the S3 resource
      const s3Client = new S3Client({
        region,
        credentials: {
          accessKeyId: s3Resource.accessKey, // Use access key from the S3 resource
          secretAccessKey: s3Resource.secretKey, // Use secret key from the S3 resource
        },
      });
    
    
      const getCommand = new GetObjectCommand({
        Bucket: bucketName,
        Key: file.s3, // Use the key from the S3Object parameter
      });
    
      const presignedUrl = await getSignedUrl(s3Client, getCommand, { expiresIn: expiretime });
    
    
      return presignedUrl;
    
    }

    Submitted by hugo697 377 days ago

  • bun
    import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
    import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
    import { S3Object } from 'windmill-client';
    
    // Define the S3 resource type
    type S3 = {
      port: number,
      bucket: string,
      region: string,
      useSSL: boolean,
      endPoint: string,
      accessKey: string,
      pathStyle: boolean,
      secretKey: string
    }
    
    /*
    * * Generates a presigned URL for accessing an S3 object
    * @param {S3Object} file - The uploaded file
    * @param {S3} s3Resource - The S3 resource configuration
    * @param {number} expiretime - The time that the link is valid. Maximum is 604800 seconds (7 days)
    * @returns Promise<string> - The presigned URL
    */
    export async function main(file: S3Object, s3Resource: S3, expiretime: number) {
      // Use the S3 resource to get credentials and configuration
      const bucketName = s3Resource.bucket; // Use the bucket from the S3 resource
      const region = s3Resource.region; // Use the region from the S3 resource
    
    
      // Initialize S3 client with credentials from the S3 resource
      const s3Client = new S3Client({
        region,
        credentials: {
          accessKeyId: s3Resource.accessKey, // Use access key from the S3 resource
          secretAccessKey: s3Resource.secretKey, // Use secret key from the S3 resource
        },
      });
    
    
      const getCommand = new GetObjectCommand({
        Bucket: bucketName,
        Key: file.s3, // Use the key from the S3Object parameter
      });
    
      const presignedUrl = await getSignedUrl(s3Client, getCommand, { expiresIn: expiretime });
    
    
      return presignedUrl;
    
    }

    Submitted by jansteinark898 536 days ago