Getting key in S3 response

Hi there,

I’m using the S3 (non-multipart) uploader with Uppy, and I used to have this code after a successful upload:

uppy.on('upload-success', (file, response) => {
  // Get S3 key from upload.
  const data = {
    key: response.body.key,
  };
  // Store data (with key) in db (code not shown).

This was working with Uppy 2.. and now I’m trying to upgrade to 4.. and the key is no longer showing up in the response data. Any pointers to get it to show up again?

The response looks like this:

{
    "body": {
        "content-length": "406",
        "content-type": "application/xml",
        "etag": "\"...\"",
        "location": "...",
        "ETag": "\"...\""
    },
    "status": 200,
    "uploadURL": "..."
}

and it used to look like (see the bucket and key values included):

{
    "status": 201,
    "body": {
        "location": "...",
        "bucket": "...",
        "key": "...",
        "etag": "\"...\""
    },
    "uploadURL": "..."
}

Thanks!

1 Like

Hi, do you still see the key in the response of the network request tab? If not, it may be related to a bucket setting change :thinking:

Thanks @Merlijn . I’m not exactly sure what to look for in the Network tab but I do see two with the name of my bucket, e.g. https://my-bucket.s3.us-east-1.amazonaws.com/.

The first is an OPTIONS request with a 200 status but no response. It’s type and initiator is Preflight.

The second is an xhr request from uppy.js with a 201 status, which has an XML response that does in fact have the key in it; it looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<PostResponse><Location>https://my-bucket.s3.us-east-1.amazonaws.com/media%2Frecipes%2F000b8f07-8571-44b4-ac21-a835e7772d69%2Falexs-margarita-VF9HgWsi.jpg</Location><Bucket>my-bucket</Bucket><Key>media/recipes/000b8f07-8571-44b4-ac21-a835e7772d69/alexs-margarita-VF9HgWsi.jpg</Key><ETag>"blahblah"</ETag></PostResponse>

As mentioned above, when I dump the response after success via:

uppy.on('upload-success', (file, response) => {
  console.log(response);

The key is not available, and the status in 200, not 201.

Let me know if any further information would be helpful to debug.

@Merlijn is it possible it’s related to getResonseData? Trying to piece together the uppy flow when using S3 and having a hard time figuring out everything involved.

Other ideas are something with Body or AwsBody, e.g. this change:

Or something in here:

Would you mind creating a new issue? It’s better to track this on GitHub or it will get lost.

Thanks @Merlijn I went ahead and filed an issue: Response in upload-success event no longer sends `key` with AwsS3 · Issue #5586 · transloadit/uppy · GitHub