Skip to content

S3 putObject from http stream not working #72

Closed

Description

@joehoyle

Hey, not sure if I am barking up the wrong tree here. I am trying to pass a stream to putObject, like so:

 $s3->putObject(array(
    'Bucket' => 'my-bucket',
    'Key'    => 'my-object',
    'Body'   => fopen( $url, 'r' ),
    'ACL'    => Aws\S3\Enum\CannedAcl::PUBLIC_READ
));

But I get the error:

[17-Apr-2013 22:23:34 UTC] PHP Fatal error:  Uncaught Aws\S3\Exception\NotImplementedException: AWS Error Code: NotImplemented, Status Code: 501, AWS Request ID: 2E703D55A572B6F9, AWS Error Type: server, AWS Error Message: A header you provided implies functionality that is not implemented, User-Agent: aws-sdk-php2/2.2.1 Guzzle/3.3.1 curl/7.24.0 PHP/5.4.12
  thrown in phar:.../aws.phar/src/Aws/Common/Exception/NamespaceExceptionFactory.php on line 89

Is it not possible to stream a file from HTTP > S3 directly like this?

Thanks!

Activity

  1. mtdowling commented on Apr 17, 2013

    @mtdowling
    Contributor

    It's definitely possible to send a request that uses an HTTP stream.

    The problem here is that the SDK could not determine the Content-Length of the request because you passed in a stream. Because there is no Content-Length header and the HTTP protocol being used is HTTP/1.1, the SDK (specifically Guzzle) sent the request with the Transfer-Encoding: chunked header. Because Amazon S3 does not support chunked uploads, you received a 501 response.

    You should specify a "ContentLength" parameter in your $s3->putObject() call to tell the SDK the size of the file. Try something like this:

     $s3->putObject(array(
        'Bucket' => 'my-bucket',
        'Key'    => 'my-object',
        'ContentLength' => filesize($url),
        'Body'   => fopen( $url, 'r' ),
        'ACL'    => Aws\S3\Enum\CannedAcl::PUBLIC_READ
    ));
  2. joehoyle commented on Apr 17, 2013

    @joehoyle
    Author

    Hi @mtdowling

    thanks for taking a look! I tried what you suggested (and also added ContentType incase that was needed, but I still can't get it to go through, I am still getting the same error with:

    $s3->putObject(array(
        'Bucket' => 'my-bucket',
        'Key'    => 'my-object',
        'ContentLength' => 1073741824,
        'ContentType' => 'application/zip',
        'Body'   => fopen( 'http://ipv4.download.thinkbroadband.com/1GB.zip', 'r' ),
        'ACL'    => Aws\S3\Enum\CannedAcl::PUBLIC_READ,
    ));
  3. jeremeamia commented on Apr 19, 2013

    @jeremeamia
    Contributor

    It seems like we might have an issue with this particular scenario, as it seems like the Content-Length is not set properly, even when it's provided. We'll look into this and see what we can do. Sorry it is causing you problems.

  4. jeremeamia commented on Apr 19, 2013

    @jeremeamia
    Contributor

    This issue is also duplicated on the AWS forums. We will track the issue here and post the resolution on the forums.

  5. mtdowling commented on Apr 23, 2013

    @mtdowling
    Contributor

    This issue is now resolved and the fix will be available in the next tagged release. In the meantime, if you use the master branch of the SDK and the master branch of Guzzle, then you can use non-seekable HTTP streams in your PutObject requests immediately. Here's the related commit in Guzzle: guzzle/guzzle@487250f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions