2010-06-08 6 views
0

J'essaie de télécharger une image sur le serveur en utilisant l'iPhone. Je ne l'ai pas fait avant.télécharger des images sur le serveur

Mais je ne comprends pas comment je peux le faire.

Je sais comment ajouter des données de texte sur le serveur.

Mais comment ajouter les données d'image ou une image au serveur. Quelqu'un peut-il suggérer?

Répondre

1

Essayez ceci.

How to upload an image in iPhone application

et ce

How can I upload a photo to a server with the iPhone?

EDIT:

NSMutableURLRequest *urlRequest = 
    [NSMutableURLRequest requestWithURL:url]; 
    [urlRequest setHTTPMethod:@"POST"]; 
    [urlRequest setValue: 
    [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry] 
     forHTTPHeaderField:@"Content-Type"]; 

    NSMutableData *postData = 
    [NSMutableData dataWithCapacity:[data length] + 512]; 
    [postData appendData: 
    [[NSString stringWithFormat:@"--%@\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [postData appendData: 
    [[NSString stringWithFormat: 
     @"Content-Disposition: form-data; name=\"%@\"; filename=\"file.bin\"\r\n\r\n", FORM_FLE_INPUT] 
     dataUsingEncoding:NSUTF8StringEncoding]]; 
    [postData appendData:data]; 
    [postData appendData: 
    [[NSString stringWithFormat:@"\r\n--%@--\r\n", boundry] dataUsingEncoding:NSUTF8StringEncoding]]; 

    [urlRequest setHTTPBody:postData]; 

Vérifiez également la vidéo: http://www.youtube.com/watch?v=aQXaJO36I7Y

L'enfant est exp définir les choses assez facilement .Vous pouvez faire la chose avec cette vidéo.

Vous aurez également besoin d'un script php pour analyser l'image côté serveur.

+0

Son ne fonctionne pas ... aucun code n'est dere. – Rahul

Questions connexes