Skip to content

Commit

Permalink
Add Resource::open() method to make URL creation simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 14, 2024
1 parent 380678b commit f199c86
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $file= new File('large.txt');
$file->open(File::READ);

try {
$transfer= $s3->open('PUT', 'target/'.$file->filename, [
$transfer= $s3->resource('target/{0}', [$file->filename])->open('PUT', [
'x-amz-content-sha256' => SignatureV4::UNSIGNED, // Or calculate from file
'Content-Type' => 'text/plain',
'Content-Length' => $file->size(),
Expand Down
11 changes: 11 additions & 0 deletions src/main/php/com/amazon/aws/api/Resource.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ public function transmit($payload, $type= 'application/json') {
$this->serialize($this->marshalling->marshal($payload), $type)
);
}

/**
* Opens a request and returns a `Transfer` instance for writing data to
*
* @param string $method
* @param [:string] $headers
* @return com.amazon.aws.api.Transfer
*/
public function open(string $method, array $headers) {
return $this->endpoint->open($method, $this->target, $headers);
}
}

0 comments on commit f199c86

Please sign in to comment.