I'm making a client-server program for picking a file from a location on a Mac desktop and then copying it into a iPhone simulator. Then, it'll upload it to the server using the TCP protocol.
Can anyone please suggest how to do it or can suggest a site where I can learn about it. I got the following code on internet, will it perform the above required task?
if ( [[NSFileManager defaultManager] isReadableFileAtPath:source] )
[[NSFileManager defaultManager] copyPath:source toPath:destination handler:nil];
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:foldername destination:@"" files:filenamesArray tag:&tag];
Have a look at ASIHTTPRequest: http://allseeing-i.com/ASIHTTPRequest/
Following is the piece of code I use ASIHTTPRequest to upload a file.
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addPostValue:token forKey:@"token"];
[request setFile:recorderFilePath forKey:@"thefile"];
[request startSynchronous];
NOTE, the variable recorderFilePath is the path to a audio file, this is a file I created in app document directory, added following code to your header file, will help you to get your document directory.
#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.