Hi,
I'm working in a iOS app using the UIImagePickerController to get files and videos from the photo library and upload to Azure Blob storage.
For images, everything is working fine, but for videos, it fails with the following error:
Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" UserInfo={_kCFStreamErrorCodeKey=1, _kCFStreamErrorDomainKey=1}
Basically, what I'm doing is:
1.to get the file URL from the UIImagePickerController:
if mediaType == "public.movie" { let mediaURL = info[UIImagePickerController.InfoKey.mediaURL] as! NSURL uploadFileAsync(fileURL: mediaURL.filePathURL)
}
- the upload to Azure method:
func uploadFileAsync(fileURL: URL) { ...
do { let isSecureAccess = fileURL.startAccessingSecurityScopedResource()
defer{fileURL.stopAccessingSecurityScopedResource()}
let resourceValues = try fileURL.resourceValues(forKeys: [.fileSizeKey])
// Gets the Mime Type
let extUTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileURL.pathExtension as CFString, nil)?.takeUnretainedValue()
let mimeType:String = extUTI != nil ? (UTTypeCopyPreferredTagWithClass(extUTI!, kUTTagClassMIMEType)?.takeUnretainedValue() as String?) ?? defaultMimeType : defaultMimeType
let fileSize: Int = resourceValues.fileSize!
blockBlob?.properties.length = NSNumber(value: fileSize)
blockBlob?.properties.contentType = mimeType
blockBlob?.uploadFromFile(with: fileURL)
}
The error is generating from the blockBlob?.uploadFromFile(with: fileURL)
Any help is really appreciated.