Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Files uploaded using PUT contain the whole multipart body #35

Closed
evoL opened this issue Feb 28, 2014 · 4 comments
Closed

Files uploaded using PUT contain the whole multipart body #35

evoL opened this issue Feb 28, 2014 · 4 comments

Comments

@evoL
Copy link
Contributor

evoL commented Feb 28, 2014

Each file uploaded to S3 contains the whole multipart body as its content.

This could be even an AFNetworking issue, as I found a Stack Overflow question where the author has the exact same issue, but using his own S3 handling classes.

Example code:

AFAmazonS3Manager *s3 = [[AFAmazonS3Manager alloc] initWithAccessKeyID:@"access key" secret:@"secret"];

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *filePath = [dirPaths[0] stringByAppendingPathComponent:@"test.txt"];

[@"test test test" writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

[s3 putObjectWithFile:filePath destinationPath:@"test.txt" parameters:nil progress:nil success:^(id responseObject) {
    NSLog(@"Uploaded!");
} failure:^(NSError *error) {
    NSLog(@"Error: %@", error);
}];

Resulting file, as downloaded from S3:

--Boundary+FEC9EABEC1FD2A44
Content-Disposition: form-data; name="key"

test.txt
--Boundary+FEC9EABEC1FD2A44
Content-Disposition: form-data; name="file"; filename="test.txt"
Content-Type: text/plain

test test test
--Boundary+FEC9EABEC1FD2A44--
@evoL
Copy link
Contributor Author

evoL commented Feb 28, 2014

The S3 documentation seems to imply that PUT operations do not support multipart/form-data encoded uploads, which are handled by the POST method.

In that case, the solution seems to be simply performing the upload without encoding it as multipart when using the PUT method.

@bhatti
Copy link

bhatti commented Oct 22, 2014

Is there any resolution to this as I am seeing same behavior with latest code from master. I am trying to upload images and I would like to skip multi-part boundary headers so that I can display images directly when I download them. Though, I could switch to AWS SDK but I would prefer to keep using AFNetworking if there is a work around.

@evoL
Copy link
Contributor Author

evoL commented Oct 22, 2014

Try using dmzza's version, as described in this comment: #45 (comment)

@mattt
Copy link
Contributor

mattt commented Nov 29, 2014

Fixed by cc21e90.

@mattt mattt closed this as completed Nov 29, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants