i am trying to upload image using Share extension but the problem is when i add the background task it is giving me this error, It is saying nsdata is not s
It seems Up NSURLSessionUploadTask
does not support Large size NSData,
But you can give a file path to NSURLSessionUploadTask
to upload on server, or write your image temporary on disk firs then give path.
Here's an example it is uploading both the filepath and NSdata.
Uploads using backgroundSessionConfiguration and NSURLSessionUploadTask cause app to crash
Updated :
//Create a file to upload
UIImage *image = [UIImage imageNamed:@"onboarding-4@2x.png"];
NSData *imageData = UIImagePNGRepresentation(image);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *URLs = [fileManager URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSString *documentsDirectory = [[URLs objectAtIndex:0] absoluteString];
// Here's the filePath URL
NSString *filePath = [documentsDirectory stringByAppendingString:@"testfile.png"];
[imageData writeToFile:filePath atomically:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://file.upload/destination"]];
[request setHTTPMethod:@"PUT"];
// Here it is using it filePath.
NSURLSessionUploadTask *uploadTask = [upLoadSession uploadTaskWithRequest:request fromFile:[NSURL URLWithString:filePath] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
//code
}];