2013-04-03 79 views
0

我想在maultipartform的要求,在這種格式 -無法上傳使用ASIHttpFormDataRequest視頻--- iPhone

<form action="http://xyz.com/web/video/formupload/01f7e4d2-9484-44ed-9e5d-bb4b7ff67739" method="post" 
     enctype="multipart/form-data" "> 
    <input id="uploadedFile" type="file" name="uploadedFile"/> 
    <input type="hidden" name="token" value="TOKEN"/> 
    <input type="submit" value="go" /> 
</form> 

我使用asiformdatarequest類用於此目的.. 這是我下面的代碼

ASIFormDataRequest *videoUploadRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:[tokenValue objectForKey:@"url"]]]; 
    [videoUploadRequest setPostFormat:ASIMultipartFormDataPostFormat]; 
    [videoUploadRequest addData:[tokenValue objectForKey:@"token"] forKey:@"token"]; 
    [videoUploadRequest addData:video withFileName:@"New Video" andContentType:(@"video/*") forKey:@"uploadedFile"]; 

[videoUploadRequest startSynchronous]; 

NSError *error = [videoUploadRequest error]; 

if (!error) 
{ 
    NSString *response = [videoUploadRequest responseString]; 
    NSLog(@"upload response: %@", response); 
} 
else 
{ 
    NSLog(@"Eror -- %@", error); 
} 

我收到一個錯誤說

Eror -- Error Domain=ASIHTTPRequestErrorDomain Code=3 "Authentication needed" UserInfo=0x1e5ee090 {NSLocalizedDescription=Authentication needed} 

請任何人都可以告訴我們,如果有什麼錯誤的代碼..請求或其他任何 格式..

提前感謝!

+0

錯誤說你應該擁有的發送您的身份驗證參數(例如,用戶ID和密碼),然後上傳視頻。 – Tirth

+0

我已經驗證.. ,我也得到一個令牌值URL當我說我要上傳視頻 和使用我正在上傳的視頻! – Gurvinder

+0

檢查上傳服務是否有特權將視頻上傳到服務器或不... – Ganapathy

回答

0

得到了答案! 以不正確的格式發送令牌。 這是它!

NSString *string = [NSString stringWithFormat:[tokenValue objectForKey:@"url"]]; 
NSURL *url = [NSURL URLWithString:string]; 

ASIFormDataRequest *videoUploadRequest = [ASIFormDataRequest requestWithURL:url]; 
[videoUploadRequest setPostFormat:ASIMultipartFormDataPostFormat]; 

[videoUploadRequest addPostValue:[tokenValue objectForKey:@"token"] forKey:@"token"]; 
[videoUploadRequest addData:video withFileName:@"uploadedFile" andContentType:(@"video/*") forKey:@"uploadedFile"]; 

[videoUploadRequest startSynchronous]; 

NSError *error = [videoUploadRequest error]; 


if (!error) 
{ 
    NSString *response = [videoUploadRequest responseString]; 
    NSLog(@"upload response: %@", response); 
} 
else 
{ 
    NSLog(@"Error -- %@", error); 
} 
+0

請我是新iPhone發展,我想上傳一個視頻文件server.Please發佈您的整個代碼。提前致謝 –