AFNetworking/AFNetworking — Issue #138: Issues uploading files
Author: samsoffes
Created: 2011-12-04 04:40:29+00:00
State: open

I tried to run the following code:

``` objective-c
[formData appendPartWithFileData:imageData name:@"file" fileName:fileName mimeType:@"image/jpeg"];
```

But it appeared that a boundary is messed up somewhere, because it was saying the data before the file was too large. I made a really small file under the limit and it said missing file.

This is the code I am using until this gets resolved:

``` objective-c
NSString *boundary = @"Boundary+0xAbCdEfGbOuNdArY"; // The real constant is private
[formData appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[formData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", fileName] dataUsingEncoding:NSUTF8StringEncoding]];
[formData appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n", @"image/jpeg"] dataUsingEncoding:NSUTF8StringEncoding]];
[formData appendData:imageData];
[formData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
```

Everything works as expected using this workaround.

I tried to add this, but realized it wouldn't be easy for me to read through everything and solve this quickly. Hopefully the workaround will help diagnose the issue.