使用 Alamofire 下载文件 ROM Web 服务器

发布于 2025-01-16 19:03:19 字数 2448 浏览 0 评论 0原文

我正在开发一个用 swift 编写的 macos 应用程序,它可以从远程位置上传和下载文件。

上传是正确的,但是对于下载,当我从本地服务器上执行时,没有问题,但是从远程服务器上我只能得到 603 个八位字节,无论文件的大小是多少。

我不确定这是否来自我的 swift 函数(因为它与本地服务器一起使用)。 我的swift功能如下:

public func downloadFile(request: BaseRequest, progressIndicator: NSProgressIndicator?, completion: @escaping(NetworkResult<String,  NSString>) -> Void) {
        #if DEBUG
        print(request.parameters["filename"]?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "Networking.downloadFile problème URL")
        #endif
        if let progressIndicator = progressIndicator {
            progressIndicator.isIndeterminate = false
            progressIndicator.minValue = 0
            progressIndicator.maxValue = 1
            progressIndicator.startAnimation(self)
        }
        if let filename = request.parameters["filename"], let displayName = request.parameters["displayname"], let url = URL(string: filename.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) {
            let destination: DownloadRequest.Destination = { _, _ in
                var documentsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
                documentsURL.appendPathComponent(displayName)
                //print(documentsURL)
                return (documentsURL, [.removePreviousFile])
            }
            AF.download(url, to: destination)
            
                .downloadProgress(queue: .main, closure: { (progress) in
                    if let progressIndicator = progressIndicator {
                        DispatchQueue.main.async {
                            progressIndicator.doubleValue = progress.fractionCompleted
                        }
                    }
                })
            
                .responseData {
                    response in
                    switch response.result {
                    case .failure(let error):
                        completion(NetworkResult.failure(NSString(string: error.errorDescription!)))
                    case .success(_):
                        completion(NetworkResult.success(response.fileURL?.path ?? ""))
                    }
                    
                }
            
        } else {
            completion(NetworkResult.failure(NSString(string: "Impossible de récupérer le fichier, requête \(request)")))
        }
    }

在Web服务器上有什么特殊的实现(Web服务器安装在1and1上)

I'm developping a macos App written in swift which can upload and download files from a distant location.

Uploading is correct, but for downloading, when I do it from a local server, there is no problem, but from a distant server I only get 603 octets, whatever is the size of the file.

I'm not sure that this comes from my swift function (as it works with a local server).
My swift function is as following:

public func downloadFile(request: BaseRequest, progressIndicator: NSProgressIndicator?, completion: @escaping(NetworkResult<String,  NSString>) -> Void) {
        #if DEBUG
        print(request.parameters["filename"]?.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? "Networking.downloadFile problème URL")
        #endif
        if let progressIndicator = progressIndicator {
            progressIndicator.isIndeterminate = false
            progressIndicator.minValue = 0
            progressIndicator.maxValue = 1
            progressIndicator.startAnimation(self)
        }
        if let filename = request.parameters["filename"], let displayName = request.parameters["displayname"], let url = URL(string: filename.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) {
            let destination: DownloadRequest.Destination = { _, _ in
                var documentsURL = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
                documentsURL.appendPathComponent(displayName)
                //print(documentsURL)
                return (documentsURL, [.removePreviousFile])
            }
            AF.download(url, to: destination)
            
                .downloadProgress(queue: .main, closure: { (progress) in
                    if let progressIndicator = progressIndicator {
                        DispatchQueue.main.async {
                            progressIndicator.doubleValue = progress.fractionCompleted
                        }
                    }
                })
            
                .responseData {
                    response in
                    switch response.result {
                    case .failure(let error):
                        completion(NetworkResult.failure(NSString(string: error.errorDescription!)))
                    case .success(_):
                        completion(NetworkResult.success(response.fileURL?.path ?? ""))
                    }
                    
                }
            
        } else {
            completion(NetworkResult.failure(NSString(string: "Impossible de récupérer le fichier, requête \(request)")))
        }
    }

Is there something special to implement on the web server (the web server is installed on 1and1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

咽泪装欢 2025-01-23 19:03:19

忘记我的问题,问题出在我要下载的文件的权限上。权利必须是蜜蜂 0505 而不是 0606

Forget my question, the problem came about rights of the file I wanted to download. Rights have to bee 0505 and not 0606

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文