فهرست منبع

update download upload

kevin 2 سال پیش
والد
کامیت
236d3d054a

+ 12 - 5
appbuilder-ios/NexilisLite/NexilisLite/Source/Download.swift

@@ -56,15 +56,22 @@ public class Download {
         }
         let fullURL = "\(baseURL)\(sep)\(filename)"
         do {
-            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory, in: .userDomainMask, options: [.removePreviousFile, .createIntermediateDirectories])
-            let downloadRequest = AF.download(fullURL, to: destination)
+//            let destination = DownloadRequest.suggestedDownloadDestination(for: .documentDirectory, in: .userDomainMask, options: [.removePreviousFile, .createIntermediateDirectories])
+            let downloadRequest = AF.download(fullURL)
             .downloadProgress(queue: downloadBufferQueue) { progress in
                 completion(filename,progress.fractionCompleted*100)
             }
-            .response { result in
-                if let successResponse = result.value{
+            .responseData { result in
+                if let successResponse = result.value {
                     //print("Response success")
-                    completion(filename,100)
+                    do {
+                        let documentDir = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
+                        let url = documentDir.appendingPathComponent(filename)
+                        //print("write file \(url.path)")
+                        try successResponse.write(to: url)
+                        completion(filename,100)
+                    }
+                    catch {}
                 }
                 else {
                     let statusCode = result.response?.statusCode

+ 6 - 2
appbuilder-ios/NexilisLite/NexilisLite/Source/Network.swift

@@ -202,7 +202,11 @@ public class Network {
                 let documentDir = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
                 for name in filename {
                     let fileDir = documentDir.appendingPathComponent(name)
-                    filesIn.append(fileDir)
+                    let path = fileDir.path
+                    if FileManager.default.fileExists(atPath: path) {
+                        let fileURL = URL(fileURLWithPath: path)
+                        filesIn.append(fileURL)
+                    }
                 }
             }
             catch {}
@@ -215,7 +219,7 @@ public class Network {
             }
             
             for i in 0..<filesIn.count {
-                multipartFormData.append(filesIn[i], withName: "file\(i+1)")
+                multipartFormData.append(filesIn[i], withName: "file\(i+1)", fileName: filesIn[i].lastPathComponent, mimeType: "application/octet-stream")
                 //print(multipartFormData)
             }
             

+ 14 - 1
appbuilder-ios/NexilisLite/NexilisLite/Source/View/Control/ProfileViewController.swift

@@ -676,7 +676,20 @@ extension ProfileViewController: ImageVideoPickerDelegate {
                     if !FileManager.default.fileExists(atPath: fileDir.path), let data = resize.jpegData(compressionQuality: 0.8) {
                         try! data.write(to: fileDir)
                         Network().uploadHTTP(name: fileDir.lastPathComponent) { result, progress , response in
-                            guard result, progress == 100 else {
+                            guard result else {
+                                DispatchQueue.main.async {
+                                    Nexilis.hideLoader(completion: { [self] in
+                                        let imageView = UIImageView(image: UIImage(systemName: "xmark.circle.fill"))
+                                        imageView.tintColor = .white
+                                        publicBanner.dismiss()
+                                        publicBanner = FloatingNotificationBanner(title: "Can't change profile picture, try again later".localized(), subtitle: nil, titleFont: UIFont.systemFont(ofSize: 16), titleColor: nil, titleTextAlign: .left, subtitleFont: nil, subtitleColor: nil, subtitleTextAlign: nil, leftView: imageView, rightView: nil, style: .danger, colors: nil, iconPosition: .center)
+                                        publicBanner.show()
+                                        self.dismissImage?(image, fileDir.lastPathComponent)
+                                    })
+                                }
+                                return
+                            }
+                            guard progress == 100 else {
                                 return
                             }
                             if let response = Nexilis.writeAndWait(message: CoreMessage_TMessageBank.getChangePersonImage(thumb_id: fileDir.lastPathComponent)), response.isOk() {