Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Picking a file from a location for uploading to server

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];
like image 399
Junior Bill gates Avatar asked May 20 '11 06:05

Junior Bill gates


People also ask

What does connect to server mean in Files iPhone?

You can use the Files app to access files stored on file servers, other cloud storage providers like Box and Dropbox, and external devices, such as USB drives and SD cards, after you connect them to your iPhone.


1 Answers

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"]
like image 107
Dongsheng Cai Avatar answered Oct 23 '22 03:10

Dongsheng Cai