使用 Alamofire 下载文件 ROM Web 服务器
我正在开发一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
忘记我的问题,问题出在我要下载的文件的权限上。权利必须是蜜蜂 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