larryq
larryq

Reputation: 16299

Programmatically determine whether a file prefix exists in an S3 bucket

We're using AWS S3 to store file streams generated from MP3s. We want to spot check that the upload process worked correctly (ideally using a program in Node.js) by looping over a list of 'songIds' of ours and checking the bucket to make sure at least one file is in there corresponding to it.

So for example, a songId of 3423455 would have entries in the bucket starting with '35423455'-- they'd be called 35423455a1.ts, 35423455a2.ts...etc. All we want to see is if something in the bucket has a name starting with the songId.

I've looked at some of the docs and the listObjects [edit-- looks like 'listObjectsV2' is even better] method appears to have promise, would this be a good way to go about it? Can I use a file prefix in the params section of the method call?

Upvotes: 0

Views: 698

Answers (1)

jellycsc
jellycsc

Reputation: 12259

Yes, listObjects is a perfect fit for this use case. Actually, it's better to use listObjectsV2.

Upvotes: 2

Related Questions