views:

37

answers:

1

So I have an application that currently upload images to a web service using a multipart form and I do this pretty simply using an NSMutableRequest and NSURLConnection. The problem I seem to be coming into though is I want to be able to upload a given file without loading it into the program as an NSData object, but simply from the file path. I have heard that this is possible and I know the ASIHTTPRequest seems to do it. Any help would be much appreciated! Thank you!

+1  A: 

You're mistaken. You can't just send a file path to the remote server, because the server would still just have the path, but none of the contents of the file. Even ASIHTTPRequest is still reading the file into memory and creating the HTTP request with the file contents in the request body. They just have a nicer API for doing it.

So technically, you can just post a file by providing a path to ASIHTTPRequest, but ASIHTTPRequest is just doing the dirty work for you. At some point you're going to have to load the file into memory.

An alternative would be to create a custom NSInputStream subclass (let's call it HTTPPostStream) that dynamically builds the HTTP POST body, given some file paths and what not. Then it could stream bytes directly off the disk and into the outgoing request, saving you from loading a large file into memory. This will be more work, but you won't have to worry about loading a 2GB file into memory.

For simplicity, though, ASIHTTPRequest looks pretty decent.

Dave DeLong
I do love ASIHTTPRequest and would use it in most cases, but I am just trying to get the system down for how it works.When I said that I didn't want to load it into memory entirely, I meant that I did not want to load 100MB into one NSData object but more do so incrementally like you mentioned. I friend of mine did mention that that could be achieved with an NSURLConnection but I am not entirely sure as to how.I will take a look at NSInputStreams and get back to you when I found out some more, thank you!
Sj
@Sj I'll also look into NSInputStreams, since this has intrigued me. :)
Dave DeLong