नीचे अपलोड करने के लिए, एक छवि file.I केवल NSURLSessionUploadTask उपयोग करना चाहते हैं अपलोड करने के लिए छोटा सा अंश है, क्योंकि यह पृष्ठभूमि अपलोड सुविधा जो मैं अपने अनुप्रयोग में उपयोग करना चाहते हैं देता है असफल रहा।NSURLSessionUploadTask फ़ाइल
इसके अलावा मैं फ़ाइल अपलोड के साथ पैरामीटर पोस्ट करना चाहता हूं।
इसके अलावा मैं सर्वर साइड में अच्छा नहीं हूँ code.Can किसी को भी कृपया मुझे मार्गदर्शन क्या मैं गलत कर रहा हूं।
अपलोड कोड
NSString* filePath = [[NSBundle mainBundle]
pathForResource:@"sample" ofType:@"jpg"];
uint64_t bytesTotalForThisFile = [[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:NULL] fileSize];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:uploadPath];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"%llu", bytesTotalForThisFile] forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
[request setTimeoutInterval:30];
NSString* filePath = [[NSBundle mainBundle]
pathForResource:@"sample" ofType:@"jpg"];
NSURLSessionUploadTask *taskUpload= [self.uploadSession uploadTaskWithRequest:request fromFile:[[NSURL alloc] initFileURLWithPath:filePath]];
पीएचपी कोड
<?php
$objFile = & $_FILES["file"];
$strPath = basename($objFile["name"]);
if(move_uploaded_file($objFile["tmp_name"], $strPath)) {
print "The file " . $strPath . " has been uploaded.";
} else {
print "There was an error uploading the file, please try again!";
}
सर्वर की ओर से मैं मैं कोड का एक उदाहरण रखा जाएगा $ _FILES
मैं पृष्ठभूमि सत्र का उपयोग कर रहा डिफ़ॉल्ट नहीं, इसके अलावा पूरा होने हैंडलर पृष्ठभूमि session.Also NSData में अनुमति नहीं है के रूप में छवि छवि के रूप में अनुमति नहीं है। – Mukesh