मुझे आपकी समस्या का पता है .. मैंने मुस्कुराते हुए मुद्दे का सामना किया है .. आपको छवि के लिए पथ देना होगा .. निम्न कोड पथ से छवि प्राप्त करेगा .. यदि छवि आपकी निर्देशिका अनुक्रमणिका में है तो आपको प्राप्त करना होगा रास्ता थोड़ा अलग है.. इसे आज़माएं और मुझे बताएं..
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"photo.jpg"];
[request setFile:[NSURL URLWithString:dataPath] forKey:@"photo"];
//IF the photo is in directory index use the following code to get the url
NSString *filename = [[NSBundle mainBundle] pathForResource:@"photo" ofType:@"png"];
[request setFile:[NSURL URLWithString:filename] forKey:@"photo"];
ठीक है यहाँ वह कोड है जो आपको UIImagePicker के लिए लिखना है
- (void) imagePickerController:(UIImagePickerController *)thePicker didFinishPickingMediaWithInfo:(NSDictionary *)imageInfo
{
imagePicker = nil;
UIImage *image = [imageInfo objectForKey:@"UIImagePickerControllerEditedImage"];
image = [image roundedCornerImage:23.5 borderSize:1];
// Get the data for the image as a JPEG
NSData* imageData = UIImageJPEGRepresentation(image, 0.5);
// Give a name to the file
NSString* imageName = @"photo.png";
// Now, we have to find the documents directory so we can save it
// Note that you might want to save it elsewhere, like the cache directory, or something similar.
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPathToFile atomically:NO];
myPicture = imageData;
myPicturePath = fullPathToFile;
// Dismissing the image picker view
[self dismissModalViewControllerAnimated: YES];
}
छवि अपलोड करते समय इस कोड का उपयोग करें .. आपके पास छवि पिकर से myPicture पथ सेट होगा ..
Request setFile:myPicturePath forKey:@"photo"];
दस्तावेज़ निर्देशिका से छवि प्राप्त करने और उसे भेजने के लिए निम्न कोड है..
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:@"photo.png"];
[imageData writeToFile:fullPathToFile atomically:NO];
[Request setFile:fullPathToFile forKey:@"photo"];