Giter VIP home page Giter VIP logo

Comments (4)

kherock avatar kherock commented on June 16, 2024

Could you provide a more detailed example resembling your internal tests? I'm not too familiar with how s3.createPresignedPostinteracts with the S3 API. My guess is that the POST endpoint just needs to be made case-insensitive when reading request body parameters.

from s3rver.

etc-tiago avatar etc-tiago commented on June 16, 2024

Of course!

The idea of s3.createPresignedPost is to upload directly to S3 on the frontend. And also for uploading files larger than API Gateway (10mb) and EC2 can support or have a higher price for this function.

Then you can create a link (server) with parameters for submission and add it to a form (client).

So let's say you add the filename that will be inside s3, control the expiry time and set the upload condition, something like:

{
  Bucket: "example",
  Key: "path/of/file.pdf",
  Conditions: [["content-length-range", 0, 10240000]], // optional
  Expires: 3600,
}

To use in form:

// URL_VALUE url to upload
// VALUE params to use on upload
<form action="URL_VALUE" method="post" enctype="multipart/form-data">
  <input type="hidden" name="key" value="VALUE" />
  <input type="hidden" name="AWSAccessKeyId" value="VALUE" />
  <input type="hidden" name="policy" value="VALUE" />
  <input type="hidden" name="signature" value="VALUE" />
  File:
  <input type="file" name="file" /> <br />
  <input type="submit" name="submit" value="Upload to Amazon S3" />
</form>

For some reason, in the documentation it displays as key and in the code as Key:
Docs: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_s3_presigned_post.html
Code: https://github.com/aws/aws-sdk-js-v3/blob/72611ca19b/packages/s3-presigned-post/src/createPresignedPost.ts#L19

In order for the code to work on AWS, I needed to change from <input type="hidden" name="key" value="VALUE" /> to <input type="hidden" name="Key" value="VALUE" />, but the process fails in place.

In order for it to work with S3rver, I changed all references from key to Key. The rest of the S3 sending and receiving processes, such as profile photo, were not affected and work in both cases in s3rver and aws.

I think the process used refers to the uploadPart function:

exports.uploadPart = async function uploadPart(ctx) {

I think the simplest solution would be to check if the Key exists when key does not exist, because has 2 references when use uploadPart:

exports.getObjectTagging = async function getObjectTagging(ctx) {
const key = ctx.params.key;
const exists = await ctx.store.existsObject(ctx.params.bucket, key);
if (!exists) {
throw new S3Error('NoSuchKey', 'The specified key does not exist.', {
Key: key,
});
}

and

exports.putObjectTagging = async function putObject(ctx) {
const key = ctx.params.key;
const bucket = ctx.params.bucket;
const exists = await ctx.store.existsObject(bucket, key);
if (!exists) {
throw new S3Error('NoSuchKey', 'The specified key does not exist.', {
Key: key,
});
}

Maybe can use like:

const key = ctx.params.key || ctx.params.Key;

But for now it's all guesswork, I don't have the opportunity and time to analyze each process in depth.

from s3rver.

etc-tiago avatar etc-tiago commented on June 16, 2024

I submitted a pull request that allows this change without braking changes. #750

from s3rver.

kherock avatar kherock commented on June 16, 2024

It still looks like the parameter name sent over the wire is lowercase. From the same file you linked in the JS SDK it takes the capitalized parameter name and sends it as lowercase:
https://github.com/aws/aws-sdk-js-v3/blob/72611ca19bfe43ae6cee0e65dbb0a83689f76c5d/packages/s3-presigned-post/src/createPresignedPost.ts#L92

This aligns with the POST Object docs
https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPOST.html#RESTObjectPOST-requests-form-fields

from s3rver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.