bdbergeron / BDBOAuth1Manager

OAuth 1.0a library for AFNetworking 2.x
MIT License
100 stars 35 forks source link

Unauthorized when upload file #38

Closed Stefanus-Januar closed 9 years ago

Stefanus-Januar commented 9 years ago

Hi, I'm trying to migrate the old code from RSOAuthEngine to BDBOAuth1Manager (1.5.0). The migration run smoothly with login, logout, POST, and GET.

The problem comes when I try to upload image to the server and get Request failed: unauthorized (401).

NSURLSessionDataTask *task = [_networkManager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {

        [formData appendPartWithFormData:imagedata name:imagekey];

    } success:^(NSURLSessionDataTask *task, id responseObject) {

        // Success 

    } failure:^(NSURLSessionDataTask *task, NSError *error) {

       // Fail
    }];
kolpanic commented 9 years ago

@Stefanus-Januar Are you using AFNetworking 2.6, and do your parameters include values with slashes? If so, it may be related to #36.

Stefanus-Januar commented 9 years ago

Hi @kolpanic thx for your reply. I think it's a different issue because the parameters is nil. I also have tried with AFNetworking 2.6 and BDBOAuth1Manager (latest commit) but still get same error.

If somebody has sample project with upload file, it will help a lot.

Here is the input :

URLString : "https://www.domain.com/api/oauth/image"
parameters : nil
imagedata : (NSData)
imagekey : "image"
Stefanus-Januar commented 9 years ago

After investigation,finally I found MKNetworkit used fileName "file" as default.

So I change my code and it works.

 [formData appendPartWithFileData:imagedata name:imagekey fileName:@"file" mimeType:@"application/octet-stream"];