Newbie having issues with uploading a file using ASIHTTPRequest

前端 未结 1 1080
抹茶落季
抹茶落季 2020-12-15 14:46

I could really, really, really use some help. I have looked everywhere on some detailed documentation (for dummies) on using ASIFormDataRequest for photo uploads. Can some

相关标签:
1条回答
  • 2020-12-15 15:10

    I faced similar problem, i re-sized the image using

    UIImage *im = [info objectForKey:@"UIImagePickerControllerOriginalImage"] ;
    UIGraphicsBeginImageContext(CGSizeMake(320,480)); 
    [im drawInRect:CGRectMake(0, 0,320,480)];
    newImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext();
    NSData* imageData=UIImageJPEGRepresentation(newImage, 0.5); 
    

    and it started working, the height and width of the captured image will be more than 2000x2000 so reduce it and give a try.

    [request setData:imageData withFileName:@"photo.jpg" andContentType:@"image/jpeg" forKey:@"file"];
    

    and this is the php script.

    $filename="uploaded";
    $target_path = "uploads/";
    $target_path = $target_path .$filename.".jpg"; 
    if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
    echo "uploaded an image";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    0 讨论(0)
提交回复
热议问题