|
@@ -814,61 +814,53 @@
|
|
|
|
|
|
// VIDEO
|
|
|
if (assetMediaType == PHAssetMediaTypeVideo) {
|
|
|
-
|
|
|
- @autoreleasepool {
|
|
|
|
|
|
+ @autoreleasepool {
|
|
|
+
|
|
|
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
|
|
|
- options.networkAccessAllowed = true;
|
|
|
-
|
|
|
- [[PHImageManager defaultManager] requestPlayerItemForVideo:asset options:options resultHandler:^(AVPlayerItem * _Nullable playerItem, NSDictionary * _Nullable info) {
|
|
|
-
|
|
|
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]])
|
|
|
- [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] error:nil];
|
|
|
+ options.version = PHVideoRequestOptionsVersionOriginal;
|
|
|
|
|
|
- AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:playerItem.asset presetName:AVAssetExportPresetHighestQuality];
|
|
|
-
|
|
|
- if (exportSession) {
|
|
|
-
|
|
|
- exportSession.outputURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName]];
|
|
|
- exportSession.outputFileType = AVFileTypeQuickTimeMovie;
|
|
|
+ [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
|
|
|
|
|
|
- [exportSession exportAsynchronouslyWithCompletionHandler:^{
|
|
|
+ if ([asset isKindOfClass:[AVURLAsset class]]) {
|
|
|
|
|
|
- if (AVAssetExportSessionStatusCompleted == exportSession.status) {
|
|
|
-
|
|
|
- [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
-
|
|
|
- } else if (AVAssetExportSessionStatusFailed == exportSession.status) {
|
|
|
-
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
-
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
- // Error for uploadFileFailure
|
|
|
- if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
- [delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
|
|
|
- });
|
|
|
-
|
|
|
- } else {
|
|
|
- NSLog(@"Export Session Status: %ld", (long)exportSession.status);
|
|
|
- }
|
|
|
- }];
|
|
|
+ NSData *data = [[NSData alloc] initWithContentsOfURL:[(AVURLAsset *)asset URL] options:0 error:&error];
|
|
|
+
|
|
|
+ if (!error || [data length] > 0) {
|
|
|
+
|
|
|
+ [data writeToFile:[NSString stringWithFormat:@"%@/%@", _directoryUser, fileName] options:NSDataWritingAtomic error:&error];
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (!error)
|
|
|
+ error = [NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil];
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- // Activity
|
|
|
- [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+ error = [NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil];
|
|
|
+ }
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ if (error) {
|
|
|
+
|
|
|
+ // Activity
|
|
|
+ [[NCManageDatabase sharedInstance] addActivityClient:fileName fileID:assetLocalIdentifier action:k_activityDebugActionUpload selector:selector note:NSLocalizedString(@"_read_file_error_", nil) type:k_activityTypeFailure verbose:k_activityVerboseDefault activeUrl:_activeUrl];
|
|
|
+
|
|
|
// Error for uploadFileFailure
|
|
|
if ([delegate respondsToSelector:@selector(uploadFileFailure:fileID:serverUrl:selector:message:errorCode:)])
|
|
|
[delegate uploadFileFailure:nil fileID:nil serverUrl:serverUrl selector:selector message:@"_read_file_error_" errorCode:[NSError errorWithDomain:@"it.twsweb.cryptocloud" code:kCFURLErrorFileDoesNotExist userInfo:nil].code];
|
|
|
- });
|
|
|
- }
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ [self upload:fileName serverUrl:serverUrl cryptated:cryptated template:NO onlyPlist:NO fileNameTemplate:nil assetLocalIdentifier:assetLocalIdentifier session:session taskStatus:taskStatus selector:selector selectorPost:selectorPost errorCode:errorCode delegate:delegate];
|
|
|
+ }
|
|
|
+ });
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// IMAGE
|
|
|
if (assetMediaType == PHAssetMediaTypeImage) {
|
|
|
|