|
@@ -379,6 +379,8 @@ import Queuer
|
|
|
#if !EXTENSION
|
|
|
NCNetworkingE2EE.shared.upload(metadata: tableMetadata.init(value: metadata), account: account, completion: completion)
|
|
|
#endif
|
|
|
+ } else if metadata.chunk {
|
|
|
+ uploadChunkFile(metadata: tableMetadata.init(value: metadata), account: account, completion: completion)
|
|
|
} else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierUpload {
|
|
|
uploadFile(metadata: tableMetadata.init(value: metadata), account: account, completion: completion)
|
|
|
} else {
|
|
@@ -404,6 +406,8 @@ import Queuer
|
|
|
#if !EXTENSION
|
|
|
NCNetworkingE2EE.shared.upload(metadata: tableMetadata.init(value: extractMetadata), account: account, completion: completion)
|
|
|
#endif
|
|
|
+ } else if metadata.chunk {
|
|
|
+ self.uploadChunkFile(metadata: tableMetadata.init(value: extractMetadata), account: account, completion: completion)
|
|
|
} else if metadata.session == NCCommunicationCommon.shared.sessionIdentifierUpload {
|
|
|
self.uploadFile(metadata: tableMetadata.init(value: extractMetadata), account: account, completion: completion)
|
|
|
} else {
|
|
@@ -443,6 +447,56 @@ import Queuer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func uploadChunkFile(metadata: tableMetadata, account: tableAccount, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
+
|
|
|
+ let serverUrlFileName = metadata.serverUrl + "/" + metadata.fileName
|
|
|
+ let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView)!
|
|
|
+ var uploadTask: URLSessionTask?
|
|
|
+ let description = metadata.ocId
|
|
|
+
|
|
|
+ /*
|
|
|
+ // https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0
|
|
|
+
|
|
|
+ let folder = NSUUID().uuidString
|
|
|
+ let serverUrlFileName = metadata.urlBase + "/" + NCUtilityFileSystem.shared.getDAV() + "/upload/" + account.userId + "/" + folder
|
|
|
+
|
|
|
+ NCCommunication.shared.createFolder(serverUrlFileName) { (account, ocId, date, errorCode, errorDescription) in
|
|
|
+
|
|
|
+ if errorCode == 0 {
|
|
|
+
|
|
|
+ let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)!
|
|
|
+ let filesNameOut = self.fileChunks(path: path, fileName: metadata.fileName, pathChunks: path, size: 10)
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ NCCommunication.shared.upload(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, dateCreationFile: metadata.creationDate as Date, dateModificationFile: metadata.date as Date, customUserAgent: nil, addCustomHeaders: nil, requestHandler: { (request) in
|
|
|
+
|
|
|
+ self.uploadRequest[fileNameLocalPath] = request
|
|
|
+
|
|
|
+ }, taskHandler: { (task) in
|
|
|
+
|
|
|
+ uploadTask = task
|
|
|
+ NCManageDatabase.shared.setMetadataSession(ocId: metadata.ocId, sessionError: "", sessionTaskIdentifier: task.taskIdentifier, status: NCGlobal.shared.metadataStatusUploading)
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterUploadStartFile, userInfo: ["ocId":metadata.ocId])
|
|
|
+
|
|
|
+ }, progressHandler: { (progress) in
|
|
|
+
|
|
|
+ NotificationCenter.default.postOnMainThread(name: NCGlobal.shared.notificationCenterProgressTask, userInfo: ["account":metadata.account, "ocId":metadata.ocId, "serverUrl":metadata.serverUrl, "status":NSNumber(value: NCGlobal.shared.metadataStatusInUpload), "progress":NSNumber(value: progress.fractionCompleted), "totalBytes":NSNumber(value: progress.totalUnitCount), "totalBytesExpected":NSNumber(value: progress.completedUnitCount)])
|
|
|
+
|
|
|
+ }) { (account, ocId, etag, date, size, allHeaderFields, error, errorCode, errorDescription) in
|
|
|
+
|
|
|
+ self.uploadRequest[fileNameLocalPath] = nil
|
|
|
+ self.uploadComplete(fileName: metadata.fileName, serverUrl: metadata.serverUrl, ocId: ocId, etag: etag, date: date, size: size, description: description, task: uploadTask!, errorCode: errorCode, errorDescription: errorDescription)
|
|
|
+
|
|
|
+ completion(errorCode, errorDescription)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func uploadFileInBackground(metadata: tableMetadata, account: tableAccount, completion: @escaping (_ errorCode: Int, _ errorDescription: String)->()) {
|
|
|
|
|
|
var session: URLSession?
|
|
@@ -601,35 +655,6 @@ import Queuer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func createChunk(metadata: tableMetadata, account: tableAccount) -> tableMetadata? {
|
|
|
-
|
|
|
- if metadata.chunk {
|
|
|
-
|
|
|
- // https://server/remote.php/dav/uploads/roeland/myapp-e1663913-4423-4efe-a9cd-26e7beeca3c0
|
|
|
-
|
|
|
- let folder = NSUUID().uuidString
|
|
|
- let serverUrlFileName = metadata.urlBase + "/" + NCUtilityFileSystem.shared.getDAV() + "/upload/" + account.userId + "/" + folder
|
|
|
-
|
|
|
- NCCommunication.shared.createFolder(serverUrlFileName) { (account, ocId, date, errorCode, errorDescription) in
|
|
|
-
|
|
|
- if errorCode == 0 {
|
|
|
-
|
|
|
- let path = CCUtility.getDirectoryProviderStorageOcId(metadata.ocId)!
|
|
|
- let filesNameOut = self.fileChunks(path: path, fileName: metadata.fileName, pathChunks: path, size: 10)
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- return metadata
|
|
|
- }
|
|
|
-
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
@objc func verifyUploadZombie() {
|
|
|
|
|
|
var session: URLSession?
|