Asihttprequest upload file

2019-04-15 14:59发布

问题:

imusing Asihttprequest to upload file to a server, i have 2 questions :

  1. the progressView is not moving smoothly, in fact it move to the and when upload is finish.
  2. when i try to upload a big image (> 2 mo approximately ) the upload fail .

hers is my code :

 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http:xxxxx" ]];
[request setDownloadProgressDelegate:progresse];
[request setPostValue:@"upload" forKey:@"action"];  
[request addData:[NSData dataWithData:UIImageJPEGRepresentation([UIImage imageNamed:@"xxxxx.jpg"],0.9)] withFileName:@"img.jpg" andContentType:@"image/jpeg" forKey:@"img"];

[request startAsynchronous];

server side :

   if(isset($_FILES['img']))
    { 
         $dossier = 'upload/';
         $fichier = basename($_FILES['img']['name']);
         if(move_uploaded_file($_FILES['img']['tmp_name'], $dossier . $fichier)) 

         {
              echo 'ok!';
         }
         else 
         {
              echo 'fail !';
         }
    }

think you.

回答1:

  1. Try setting the uploadProgressDelegate instead.
  2. This is likely a server-side limitation, not a client issue.