Skip to content

Commit d0946f6

Browse files
committed
Merge pull request andrewrk#107 from gswalden/patch-1
add examples section to README.md w/ check if file exists
2 parents 51c4fec + d368d8f commit d0946f6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,28 @@ Returns an `EventEmitter` with these events:
600600
* `'copySuccess' (data)`
601601
* `'end' (data)`
602602

603+
## Examples
604+
605+
### Check if a file exists in S3
606+
607+
Using the AWS SDK, you can send a HEAD request, which will tell you if a file exists at `Key`.
608+
609+
See http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#headObject-property
610+
611+
```js
612+
var client = require('s3').createClient({ /* options */ });
613+
client.s3.headObject({
614+
Bucket: 's3 bucket name',
615+
Key: 'some/remote/file'
616+
}, function(err, data) {
617+
if (err) {
618+
// file does not exist (err.statusCode == 404)
619+
return;
620+
}
621+
// file exists
622+
});
623+
```
624+
603625
## Testing
604626

605627
`S3_KEY=<valid_s3_key> S3_SECRET=<valid_s3_secret> S3_BUCKET=<valid_s3_bucket> npm test`

0 commit comments

Comments
 (0)