Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 Signed Upload URLs #8

Open
akatora28 opened this issue Nov 19, 2024 · 0 comments
Open

S3 Signed Upload URLs #8

akatora28 opened this issue Nov 19, 2024 · 0 comments

Comments

@akatora28
Copy link

Would it be within the scope of this package (and by extension then the @adonisjs/drive package) to include a method for generating signed urls for file uploads?

Thinking basically the same as getSignedUrl just modified to use the createPutObjectCommand instead of createGetObjectCommand

/**
 * Returns a signed URL for uploading objects directly to S3. 
 */
async getSignedUploadUrl(key: string, options?: SignedURLOptions): Promise<string> {
  const { contentType, expiresIn, ...rest } = Object.assign({}, options);

  const signedURLOptions: PutObjectCommandInput = {
    Key: key,
    Bucket: this.options.bucket,
    ContentType: contentType,
    ...rest,
  };

  return getSignedUrl(
    this.#client,
    this.createPutObjectCommand(this.#client, signedURLOptions),
    { expiresIn: string.seconds.parse(expiresIn || '30mins') }
  );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant