File upload doesn't use file name #98

Closed
zachwaugh opened this Issue Nov 1, 2011 · 5 comments

Comments

Projects
None yet
2 participants
@zachwaugh
Contributor

zachwaugh commented Nov 1, 2011

When uploading a file with - (void)appendPartWithFileData:(NSData *)data mimeType:(NSString *)mimeType name:(NSString *)name, it replaces the actual name of the file with a name based on the current time and mime type

NSString *fileName = [[NSString stringWithFormat:@"%@-%d", name, [[NSDate date] hash]] stringByAppendingPathExtension:[mimeType lastPathComponent]];

I can see the benefit of this on iOS, when uploading something like a photo that might not have a real file name, but in general, I would want the actual file name to be sent with the upload. Also, it be really nice to have mime type automatically detected as well.

@mattt

This comment has been minimized.

Show comment
Hide comment
@mattt

mattt Nov 1, 2011

Contributor

Previously, AFMultipartFormData did have the method - (void)appendPartWithFile:mimeType:fileName:error:, but I pulled it because it was being confused with the file data version. But yeah—thanks for your suggestion. I'll tinker around to figure out the best way to add that functionality.

Contributor

mattt commented Nov 1, 2011

Previously, AFMultipartFormData did have the method - (void)appendPartWithFile:mimeType:fileName:error:, but I pulled it because it was being confused with the file data version. But yeah—thanks for your suggestion. I'll tinker around to figure out the best way to add that functionality.

@zachwaugh

This comment has been minimized.

Show comment
Hide comment
@zachwaugh

zachwaugh Nov 1, 2011

Contributor

Thanks! Currently converting my app from ASI to AFNetworking, and loving it so far.

For that API, I'd love a convenience method like - (void)appendPartWithFile:(NSString *)path name:(NSString *)name that automatically figured out the mime type and file name, and pulled the NSData object from the file. Maybe that calls a lower-level method like this, for when you need complete control:

- (void)appendPartWithFileData:(NSData *)data fileName:(NSString *)fileName mimeType:(NSString *)mimeType name:(NSString *)name

If mime type is nil, automatically detect it. If fileName is nil, create it like the current method. That be the best of both worlds (for me at least).

Contributor

zachwaugh commented Nov 1, 2011

Thanks! Currently converting my app from ASI to AFNetworking, and loving it so far.

For that API, I'd love a convenience method like - (void)appendPartWithFile:(NSString *)path name:(NSString *)name that automatically figured out the mime type and file name, and pulled the NSData object from the file. Maybe that calls a lower-level method like this, for when you need complete control:

- (void)appendPartWithFileData:(NSData *)data fileName:(NSString *)fileName mimeType:(NSString *)mimeType name:(NSString *)name

If mime type is nil, automatically detect it. If fileName is nil, create it like the current method. That be the best of both worlds (for me at least).

mattt added a commit that referenced this issue Nov 7, 2011

[Issue #98] Adding AFHTTPClient -appendPartWithFileURL:name:error:
Changing -appendPartWithFileData:mimeType:name: to -appendPartWithFileData:name:fileName:mimeType:
@mattt

This comment has been minimized.

Show comment
Hide comment
@mattt

mattt Nov 7, 2011

Contributor

9a91afe Adds - (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error, which should do pretty much exactly what you were looking for (I hope). I also changed the other file data method to take a filename argument, rather than auto-generating one. Let me know how that works for you!

Contributor

mattt commented Nov 7, 2011

9a91afe Adds - (void)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error, which should do pretty much exactly what you were looking for (I hope). I also changed the other file data method to take a filename argument, rather than auto-generating one. Let me know how that works for you!

@zachwaugh

This comment has been minimized.

Show comment
Hide comment
@zachwaugh

zachwaugh Nov 9, 2011

Contributor

Thanks, those methods are exactly what I was looking for. Just tried it out and worked perfectly.

Contributor

zachwaugh commented Nov 9, 2011

Thanks, those methods are exactly what I was looking for. Just tried it out and worked perfectly.

@mattt

This comment has been minimized.

Show comment
Hide comment
@mattt

mattt Nov 9, 2011

Contributor

Awesome! So glad to hear it. Thanks for opening this issue—really glad to have this new method in there.

Contributor

mattt commented Nov 9, 2011

Awesome! So glad to hear it. Thanks for opening this issue—really glad to have this new method in there.

@mattt mattt closed this Nov 9, 2011

egrim pushed a commit to egrim/AFNetworking that referenced this issue Sep 18, 2012

[Issue #98] Adding AFHTTPClient -appendPartWithFileURL:name:error:
Changing -appendPartWithFileData:mimeType:name: to -appendPartWithFileData:name:fileName:mimeType:

greghe pushed a commit to skillz/AFNetworking that referenced this issue Sep 3, 2015

[Issue #98] Adding AFHTTPClient -appendPartWithFileURL:name:error:
Changing -appendPartWithFileData:mimeType:name: to -appendPartWithFileData:name:fileName:mimeType:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment