Skip to main content
Upload files to S3 with uploadFileToS3 (TypeScript) or upload_file_to_s3 (Python).

Using uploadFileToS3 / upload_file_to_s3

TypeScript
import { BrowserContext, Page } from "playwright-core";
import { uploadFileToS3 } from "@intuned/browser"

export default async function handler(
  params: any,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://sandbox.intuned.dev/pdfs")

  // Wait for download event and click the trigger
  const [download] = await Promise.all([
    page.waitForEvent("download"),
    page.locator("xpath=//tbody/tr[1]//*[name()='svg']").click(),
  ])

  // Upload the Playwright Download object to S3
  const uploadedFile = await uploadFileToS3({
    file: download,
    fileNameOverride: "myfile.pdf",
  })

  // Get signed URL for access
  const signedUrl = await uploadedFile.getSignedUrl()
  console.log(
    `Download uploaded file by clicking on: \x1b[1;4;36m\x1b]8;;${signedUrl}\x1b\\Click here\x1b]8;;\x1b\\\x1b[0m \n`
  )
  return uploadedFile
}

Using saveFileToS3 / save_file_to_s3

saveFileToS3 (TypeScript) or save_file_to_s3 (Python) combines downloading and uploading in one step.
TypeScript
import { BrowserContext, Page } from "playwright-core";
import { saveFileToS3 } from "@intuned/browser"

interface Params {
  // Add your params here
}

export default async function handler(
  params: Params,
  page: Page,
  context: BrowserContext
) {
  await page.goto("https://sandbox.intuned.dev/pdfs")

  // Locate the download button
  const downloadLocator = page.locator("xpath=//tbody/tr[1]//*[name()='svg']")

  // Download and upload to S3 in one step
  const uploadedFile = await saveFileToS3({
    page,
    trigger: downloadLocator,
    timeoutInMs: 15000,
  })

  // Get signed URL for access
  const signedUrl = await uploadedFile.getSignedUrl()
  console.log(
    `Download uploaded file by clicking on: \x1b[1;4;36m\x1b]8;;${signedUrl}\x1b\\Click here\x1b]8;;\x1b\\\x1b[0m \n`
  )
  return uploadedFile
}