Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No HTTP Response when direct stream uploading to Amazon S3

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')
));
like image 244
thatguy Avatar asked Aug 06 '15 07:08

thatguy


People also ask

What HTTP response code will you receive after a successful upload to an S3 bucket?

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.

Why am I getting an HTTP 403 Forbidden error when I try to upload files using the Amazon S3 console?

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.

Which HTTP code indicates a successful upload of an object to Amazon S3?

HTTP 200 code indicates a successful write to S3.

How do I get my S3 upload URL?

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.


1 Answers

putObject from the official documentation returns a Model Object and will only return the proper Model Object if putObject succeeded

like image 90
Diego Fu Avatar answered Nov 15 '22 01:11

Diego Fu