I currently have a function that grabs an mp3 file from a remote url, and uploads it to an Amazon S3 bucket.
The function seems to work fine in that the file appears in S3, however I'm concerned that while testing this on my local server using a tunnel (ngrok) the page doesn't seem to be returning any HTTP status.
It does return 200 when I download the file locally first, then upload it. As we're dealing with large audio files, I'm trying to make the first idea work in that it's more efficient (I think).
Is there a way to make the page return a HTTP status code and should I be concerned that it currently doesn't?
Here is the code snippet using the V2 Amazon SDK in PHP
$config = array('key' => AMAZON_S3_KEY,'secret' => AMAZON_S3_SECRET,'region' => 'us-west-2');
$s3 = Aws::factory($config)->get('s3')->registerStreamWrapper();
$s3->putObject(array(
'Bucket' => 'mybucket',
'Key' => 'filename.mp3',
'ContentLength' => $size,
'Body' => fopen($url, 'r')
));
Finally, S3 responds with the 204 OK response code if the upload was successful or with an appropriate error response code if something went wrong.
The "403 Forbidden" error can occur due to the following reasons: Permissions are missing for s3:PutObject to add an object or s3:PutObjectAcl to modify the object's ACL. You don't have permission to use an AWS Key Management Service (AWS KMS) key. There is an explicit deny statement in the bucket policy.
HTTP 200 code indicates a successful write to S3.
You can get the resource URL either by calling getResourceUrl or getUrl . AmazonS3Client s3Client = (AmazonS3Client)AmazonS3ClientBuilder. defaultClient(); s3Client. putObject(new PutObjectRequest("your-bucket", "some-path/some-key.
putObject from the official documentation returns a Model Object and will only return the proper Model Object if putObject succeeded
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With