iphone: télécharger l'image vers le serveur à l'aide de ASIFormDataRequest

- Je télécharger une image sur le serveur pour lequel j'ai écrit le code à l'aide NSMutableURLRequest comme ce

NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
    [request addValue:contentType forHTTPHeaderField: @"Content-Type"];
// 
// /*
//  now lets create the body of the post
//  */
    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile%@.jpg\"\r\n",self.fileID] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

Je suppose que mon script PHP de répondre correspondant à cette et fonctionne bien

comment puis-je reproduire ci-dessus dans ASIFormDataRequest?

essayé de faire ce

ASIFormDataRequest* request = [ASIFormDataRequest requestWithURL: 
                               [NSURL URLWithString:photoUploadURLString]]; 


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

    NSMutableData *body = [NSMutableData data];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];    
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"ipodfile%@.jpg\"\r\n",self.fileID] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[NSData dataWithData:imageData]];
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

[request addData:body withFileName:filename andContentType:@"image/jpeg" forKey:@"snapshot[image]"]; 
request.uploadProgressDelegate = self.progressView; 
[request setDidFinishSelector:@selector(getFacebookPhotoFinished:)];

mais il n'a pas eu de succès?

voici les détails de mes scripts PHP

<?php 

$uploaddir = './uploads/';
$file = basename($_FILES['userfile']['name']);
$uploadfile = $uploaddir . $file;

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        echo "http://example.com/uploads/{$file}";
}

?>

Je n'ai, comme par Cyprien

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"images/ipodfile%@.jpg", fileID]];
NSData *imageData = UIImageJPEGRepresentation([itemImageView image], 0.05);
if (imageData != nil) {
    [imageData writeToFile:savedImagePath atomically:YES];
}
if ([[NSFileManager defaultManager] createFileAtPath:savedImagePath contents:imageData attributes:nil])
{
    NSLog(@"Image saved");
} else {
    NSLog(@"Image not saved");
}           


[activityIndicator startAnimating];
NSString *photoUploadURLString = @"http://example.com/imageuploader.php";

NSString* filename = [NSString stringWithFormat:@"ipodfile%@.jpg", self.fileID];
NSLog(@"url  is %@/%@",photoUploadURLString, filename);

UIImage *newImage = [[UIImage alloc] init];
newImage=[itemImageView image];
NSURL *url=[NSURL URLWithString:photoUploadURLString];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"userfile" forKey:@"name"];
[request setPostValue:filename forKey:@"filename"];

[request setData:imageData withFileName:filename andContentType:@"image/jpeg" forKey:@"snapshot[image]"];
Pouvez-vous être plus précis sur ce qui ne va pas?
ma question est simple comment van je poste l'image à l'aide de ASIHTTP demande, de sorte que mentionné ci-dessus script PHP peut enregistrer l'image sur le répertoire uploads
Pas d'erreur? Pas de réponse du serveur? Difficile de dire quel est le problème ici. Fournir plus de détails, je ne pense pas que nous pouvons deviner ce qui ne va pas dans votre code.
s'il vous plaît ne vous méprenez mais je ne suis pas du tout sûr de la façon de répliquer que mutable demande d'asi demande
Veuillez suivre [ce][1] Bien answerd [1]: stackoverflow.com/questions/22115587/...

OriginalL'auteur Ankit Sachan | 2011-05-07