Dosyaları iPhone'umdan FTP ile karşıya yüklemekte sorun yaşıyorum.Birden çok dosyayı http POST kullanarak yükleme POST
Web servisime gerekli tüm parametrelerle bir HTTP POST
isteği gönderiyorum. İki dosya gönderiyorum, bir resim, ikincisi ses. Resim yükleniyor, ancak ses yok. Web servisimi izlediğimde, sadece görüntü alanını yüklenen bir dosya olarak gösterir. Sesin de orada olduğunu göstermiyor.
Kodum: Ben resim yüklemek yoksa
NSString *urlString = [NSString stringWithFormat:ADD_LEAD_API_URL];
NSMutableURLRequest *postRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
// change type to POST (default is GET)
[postRequest setHTTPMethod:@"POST"];
// just some random text that will never occur in the body
NSString *stringBoundary = @"0xKhTmLbOuNdArY---This_Is_ThE_BoUnDaRyy---pqo";
// header value
NSString *headerBoundary = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",stringBoundary];
// set header
[postRequest addValue:headerBoundary forHTTPHeaderField:@"Content-Type"];
// create data
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userId\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[appDelegate.objCurrentUser.userId dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// message part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"firstName\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[firstName dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
/*** My rest of string parameters are successfully added to request ***/
// media part
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"imageUrl\"; filename=\"dummy.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: image/jpeg\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// get the image data from main bundle directly into NSData object
UIImage *img= leadImage;
NSData *imageData= UIImageJPEGRepresentation(img,90);
[postBody appendData:imageData];
// Image is being uploaded
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"recordSoundUrl\"; filename=\"%@\"\r\n", self.recordingPath] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Type: application/octet-stream\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[@"Content-Transfer-Encoding: binary\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
NSData *soundData = [NSData dataWithContentsOfFile:[appDelegate.documentDir stringByAppendingPathComponent:self.recordingPath]];
[postBody appendData:soundData];
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
// final boundary
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", stringBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
// add body to post
[postRequest setHTTPBody:postBody];
// Asynch request
NSURLConnection *conn = [NSURLConnection connectionWithRequest:postRequest delegate:self];
, o zaman ses sürer. Bu yüzden istekle sadece bir dosya gönderebiliyorum. Lütfen bana yardım edin ve herhangi bir yerde yanılmadığımı söyle.
Şimdiden teşekkürler.
Merhaba Kapil, Aynı sorunla karşı karşıyayım. Bu konuda bana yardımcı olabilir misiniz? –
Ne yapıyorsun? Yaptığım yolu kullanarak birden fazla dosya yüklemeye mi çalışıyorsun? Görüntü verisini satır ile ekledikten sonra: '[postBody appendData: imageData];' replace: '[postBody appendData: [[NSString stringWithFormat: @" -% @ \ r \ n ", stringBoundary] dataUsingEncoding: NSUTF8StringEncoding] ]; '' ile [postBody appendData: [[NSString stringWithFormat: @ "\ r \ n -% @ \ r \ n", stringBoundary] dataUsingEncoding: NSUTF8StringEncoding]] '' Umarım bu yardımcı olur –
Bu işe yaramaz .. Ben her zaman yardım etmek için buradayım –