# Aws s3 custom upload path

**URL:** <https://community.transloadit.com/t/aws-s3-custom-upload-path/15190>\
**Category:** Uppy\
**Created:** [January 11, 2020, 9:33am UTC](https://community.transloadit.com/t/aws-s3-custom-upload-path/15190 "2020-01-11T09:33:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshf](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/joshf/32/206_2.png) [@joshf](https://community.transloadit.com/u/joshf)\
**Post date:** [January 11, 2020, 9:33am UTC](https://community.transloadit.com/t/aws-s3-custom-upload-path/15190/1 "2020-01-11T09:33:14Z")

</div>

How can I upload to a custom s3 folder e.g “test” with uppy companion?

My code below:

new Uppy({ id: “uploader”, autoProceed: true })  
.use(GoogleDrive, {  
companionUrl: “url”  
})  
.use(AwsS3, {  
companionUrl: “url”  
})  
.on(“upload-success”, (file, resp) =\> {  
//do something  
});

Thanks

---

<div class="post-metadata">

**Author:** ![westcoastsuccess](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/westcoastsuccess/32/182_2.png) [@westcoastsuccess](https://community.transloadit.com/u/westcoastsuccess)\
**Post date:** [January 15, 2020, 7:56pm UTC](https://community.transloadit.com/t/aws-s3-custom-upload-path/15190/2 "2020-01-15T19:56:31Z")

</div>

I do that server side - you can see my instructions for s3 + nodeJS [here](https://community.transloadit.com/t/uppy-aws-s3-pre-signed-url-nodejs-complete-example-including-metadata-and-tags/15137).

The salient line in the server code section is (note the “Account\_Uploads/” - that’s the folder name - if the folder doesn’t exist in your s3 bucket, it will be created - I’m prepending a date stamp to the filename):

`Key:```Account_Uploads/${Date.now().toString()}-${JSON.parse(Object.keys(req.body)[0]).filename}```, // what we'll call our file - here I'm using a folder called "Account_Uploads" to put all my uploads into, then prepending a date string to the filename to avoid collisions - S3 will overwrite a file if another with the same key (i.e. name) is uploaded! We have to again extract the filename in a tedious fashion...`

Hope that’s helpful.

PS: I should add that I don’t use Companion, so YMMV…

---

<div class="post-metadata">

**Author:** ![joshf](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/joshf/32/206_2.png) [@joshf](https://community.transloadit.com/u/joshf)\
**Post date:** [January 16, 2020, 2:33pm UTC](https://community.transloadit.com/t/aws-s3-custom-upload-path/15190/3 "2020-01-16T14:33:31Z")

</div>

thank you but i already had working with my own endpoint (php) the issue is how to pass data to companion

---

<div class="post-metadata">

**Author:** ![westcoastsuccess](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/westcoastsuccess/32/182_2.png) [@westcoastsuccess](https://community.transloadit.com/u/westcoastsuccess)\
**Post date:** [January 22, 2020, 10:39pm UTC](https://community.transloadit.com/t/aws-s3-custom-upload-path/15190/4 "2020-01-22T22:39:57Z")

</div>

Sorry - just now saw your response…

What does your server side code look like? Because the S3 options section of the [Companion documentation](https://uppy.io/docs/companion/#S3-options) indicates you simply prepend the filename with the folder name (the same way I do in the example I gave) - they suggest you can use data from the “req” object, but you can use anything - “test/” in your case:

"The req parameter can be used to upload to a user-specific folder in your bucket, for example:

```
app.use(authenticationMiddleware)
app.use(uppy.app({
  s3: {
    getKey: (req, filename, metadata) => `${req.user.id}/${filename}`,
    /* auth options */
  }
}))

```

The default implementation returns the filename, so all files will be uploaded to the root of the bucket as their original file name.

```
({
  getKey: (req, filename, metadata) => filename
})

```

"

So:

```
 ({
      getKey: (req, filename, metadata) => "test/" + filename
 })

```

should work - I don’t think you have to worry about manually passing it to Companion. Does it work?
