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

PUT doesn't set a proper mimetype #106

Open
ryanmcgrath opened this issue Dec 10, 2015 · 0 comments
Open

PUT doesn't set a proper mimetype #106

ryanmcgrath opened this issue Dec 10, 2015 · 0 comments

Comments

@ryanmcgrath
Copy link

I might be missing something, but calls to putObjectWithFile don't actually set a mimetype anywhere before the AWS signature is generated. This results in the uploaded file having the incorrect mimetype when it's uploaded (so a browser, for instance, downloads it rather than displaying it if it can). If you change the mimetype after the signature has been generated your upload will be rejected due to a signature mismatch.

My (hacky) fix was to add the following...

    if([request.HTTPMethod compare:@"PUT" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
        for(NSString *keyPath in parameters) {
            [request setValue:parameters[keyPath] forHTTPHeaderField:keyPath];
        }
    }

in AFAmazonS3RequestSerializer.m's requestWithMethod:URLString:parameters:error method:

- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
                                 URLString:(NSString *)URLString
                                parameters:(NSDictionary *)parameters
                                     error:(NSError *__autoreleasing *)error

After that, I modified AFAmazonS3Manager.m and changed

        request = [self.requestSerializer requestWithMethod:method URLString:[[self.baseURL URLByAppendingPathComponent:destinationPath] absoluteString] parameters:nil error:nil];

to

        request = [self.requestSerializer 
            requestWithMethod:method 
                           URLString:[[self.baseURL URLByAppendingPathComponent:destinationPath] absoluteString] 
                         parameters:@{@"Content-Type": [response MIMEType]} 
                                    error:nil];

The mimetype is already being computed for the POST method but never gets properly set for a PUT. This annoyed me for a bit so I'm leaving it here - I don't have the time to do a proper pull request/test/etc, so maybe this helps someone else. Dealing with the official AWS libraries is a PITA in my experience so it'd be nice if this was kept up to date...

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

1 participant