0

I want to make a request in maultipartform, in this format --

<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>

I am using asiformdatarequest class for this purpose .. This is my code below

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);
}

I am getting an error saying

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

Please could anyone tell if there is something wrong with the code.. Format of the request or anything else..

Thanks in advance !

Tirth
  • 7,801
  • 9
  • 55
  • 88
Gurvinder
  • 21
  • 5
  • The error say's you should have to send your Authenticate parameters(e.g. user id and password) then upload your video. – Tirth Apr 03 '13 at 05:57
  • I am already authenticated.. and i get a token value & URL when i say i want to upload a video and using that i am uploading the video ! – Gurvinder Apr 03 '13 at 06:01
  • check whether upload service have the privilege to upload video in to the server or not... – Ganapathy Apr 03 '13 at 06:13

1 Answers1

0

Got the answer ! Was sending token in improper format. here it is !

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);
}
Gurvinder
  • 21
  • 5
  • Please I am new to iPhone Development and i want to upload a video file to server.Please post your whole code. Thanks in advance – Kirit Vaghela Jan 13 '14 at 06:00