English 中文(简体)
如何从 iphone application 上传一个音频文件到 Goodaddy 服务器上? [已关闭]
原标题:How to upload an audio file on godaddy server from iphone app? [closed]

我做了一个iphone 应用程序上传音频文件。

我还在Asp.net中制作了Webervices, 支持这个应用程序的其他功能, 并在Goodddy服务器上公布。

我要从我的iphone 应用程序上上传/ 保存服务器上的音频文件 。

我搜索过许多代码,但并不相关,也没有用处。

我该怎么做?

如何获得服务器路径, 我们可以上传文件?

请提供一些窃听器的样本代码。

最佳回答

这就是 IPOST 网络服务文件( 可以是任何文件、 图像、 视频、 音频、 视频、 任何音频) 的方式

NSString *fileName = @"myAudio";
    NSData *audioFile = [NSData dataWithContentsOfFile:@"myAudio.ext"]; //some audio
    NSString *urlString = @"http://www.something.com/someservice";
    urlString = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:urlString];
    NSString *strPostLength = [NSString stringWithFormat:@"%d", [audioFile length]];  
    NSMutableURLRequest *uRequest = [[NSMutableURLRequest alloc] init];  
    [uRequest setURL:url];  
    [uRequest setHTTPMethod:@"POST"];  
    if (audioFile)
    {
        NSMutableData *body = [NSMutableData data];

        NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
        NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
        [uRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];

        /*
         now lets create the body of the post
         */

        [body appendData:[[NSString stringWithFormat:@"
--%@
",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
        [uRequest setValue:strPostLength forHTTPHeaderField:@"Content-Length"];  
        [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name="userfile"; filename="%@.ext"
",fileName] dataUsingEncoding:NSUTF8StringEncoding]];

/ 用户文件 - & gt; 服务器代码中给出的变量名称...

        [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream

"] dataUsingEncoding:NSUTF8StringEncoding]];
        [body appendData:[NSData dataWithData:audioFile]];
        [body appendData:[[NSString stringWithFormat:@"
--%@--
",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

        // setting the body of the post to the reqeust
        [uRequest setHTTPBody:body];
    }

    NSURLConnection *uConn=[[NSURLConnection alloc] initWithRequest:uRequest delegate:self];  
    if (uConn)   
    {  
        NSLog(@"Failed to connect to url"); 
    } 
    uRequest = nil;

我希望这能帮助你 解决你的问题...

问题回答

暂无回答




相关问题
Using a file form field with a Java servlet

I am tring to retrieve a filename or the file itself for use in a java servlet (from a web form). I have a file form field: <form enctype="multipart/form-data" method="post" action="...

Streaming uploaded files directly into a database table

I have several applications that allow users to upload attachments that are stored inside a database table. This has worked fine for several years because it was initially intended for smallish image ...

Asynchronus File Upload with StateServer Mode

I want to implement Asynchronus File Upload. I ve tried ajax:AsyncFileUpload control. It s working fine only with InProc Mode. But I m using StateServer Mode. Any help from anybody? Thanks in ...

How do CMS upload images?

I am just playing around and trying to make a very simple CMS. Right now I what I do right now is I use "FtpWebRequest" to get the file that they want to change around and stick it into a jquery ...

File does not upload from web form in Django

Howdy - I ve written a very simple app to accept job applications including a resume upload. Running the bundled server for development locally, I can successfully upload files via the web form on ...

热门标签