IPhone: select a file from a location to upload to the server

I am making a client-server program to select a file from a location on the Mac desktop and then copy it to the iPhone simulator. He will then upload it to the server using the TCP protocol.

Someone can suggest how to do this or can offer a site where I can find out about it. I got the following code online, will it complete the above 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]; 
+6
source share
1 answer

Take a look at ASIHTTPRequest: http://allseeing-i.com/ASIHTTPRequest/

The following is a snippet of code. I am using 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 the sound file, this is the file that I created in the application document directory, added to the code header code, will help you get the directory of your document.

 #define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] 
+4
source

Source: https://habr.com/ru/post/888619/


All Articles