pplu / aws-sdk-perl

A community AWS SDK for Perl Programmers
Other
171 stars 94 forks source link

CreateMultipartUpload generates invalid request #92

Open frioux opened 8 years ago

frioux commented 8 years ago

Ok so I'm working on #90 and was just testing the code, and sadly I think that the implementation of CMU is broken. I try to create a multipart upload with this fairly simple call:

my $id = $s3->CreateMultipartUpload(
  Bucket => 'test.ziprecruiter.com',
  Key => 'test',
)->UploadId;

And I get the following exception:

Paws::S3 is not stable / supported / entirely developed at /usr/local/share/perl/5.14.2/Paws/S3.pm line 2.
Bad Request

Trace begun at /usr/local/share/perl/5.14.2/Paws/API/Caller.pm line 107
Paws::API::Caller::handle_response('Paws::S3=HASH(0x29dc378)', 'Paws::S3::CreateMultipartUpload=HASH(0x3308b90)', 400, '<?xml version="1.0" encoding="UTF-8"?>^J<Error><Code>IncompleteBody</Code><Message>The request body terminated unexpectedly</Message><RequestId>[ ... ]</RequestId><HostId>[ ... ]</HostId></Error>', 'HASH(0x36e5050)') called at /usr/local/share/perl/5.14.2/Paws/Net/Caller.pm line 47
Paws::Net::Caller::do_call('Paws::Net::Caller=HASH(0x276d138)', 'Paws::S3=HASH(0x29dc378)', 'Paws::S3::CreateMultipartUpload=HASH(0x3308b90)') called at /usr/local/share/perl/5.14.2/Paws/S3.pm line 111
Paws::S3::CreateMultipartUpload('Paws::S3=HASH(0x29dc378)', 'Bucket', 'test.ziprecruiter.com', 'Key', 'test') called at auto-multipart.t line 61
A::_multi_upload('A=HASH(0x20abea8)', 'GLOB(0x256ee98)', 'Bucket', 'test.ziprecruiter.com', 'Key', 'test') called at auto-multipart.t line 100
A::upload('A=HASH(0x20abea8)', 'Bucket', 'test.ziprecruiter.com', 'Key', 'test', 'fh', 'GLOB(0x256ee98)') called at auto-multipart.t line 117

On page 4 of the S3 manual that error explanation is: You did not provide the number of bytes specified by the Content-Length HTTP header

I suspect that this is some simple oversight?

pplu commented 8 years ago

Yes, It's oversight, since the S3 hasn't been completely developed in Paws (other services don't require the Content-Length header)

orbweaver commented 8 years ago

I am experiencing the same problem. I tried to add "has ContentLength" to CreateMultipartUpload.pm (see below) but it didn't seem to help. The call times out, probably because AWS is waiting for contents of the body.

Here is the line I added: has ContentLength => (is => 'ro', isa => 'Int', traits => ['ParamInHeader'], header_name => 'Content-Length' );

Have you been able to get CreateMultipartUpload working?

pplu commented 8 years ago

Even forcing a Content-Lenght header for the CreateMultipartUpload call, I can't get it to work.

Seems to be because S3 multipart upload is more involved than what is implemented right now as per http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html

If you want to give it a shot/need help, I'm willing to guide you to get the work done.

@frioux did you get anything to work?

Jose Luis

orbweaver commented 8 years ago

Thank you so much. I'll review the document that you posted and will start, next week, to try a few things. I know I will have questions, so I'm grateful for your willingness to help. Chat with you soon.

glenveegee commented 8 years ago

@orbweaver I had the same error when calling CopyObject. I've managed to get the call working for CopyObject. I suspect the changes might fix the CreateMultiPartUpload call too. If you're interested the changes are in PR#115 https://github.com/pplu/aws-sdk-perl/pull/115

castaway commented 5 years ago

Rereading the above, as well as the various documents I have some thoughts / questions: 1) Did the call send content-length at all?

The error message implies "content-length was sent, but wrong", neither the service-1.json nor the CreateMultipartUpload.pm lists content-length (and there's no stream param, so one shouldn't be added by RestXmlCaller..

2) There are a bunch of other Headers that the docs say are required, but service-1.json doesn't, eg content-type, content-encoding (see https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html ) maybe this is what caused the error? - this feels like an issue in the call definition

castaway commented 4 years ago

t/s3/multipartupload.t (in tests/stabilisation) now run/RECORD fashion against live AWS, and it works fine.