我尝试使用Alamofire上传数据
I try to upload data using Alamofire
问题是:如果我尝试从项目中上传图片,效果很好,但是如果我尝试上传zip目录,错误和超时异常
Issue is: if I try to upload image from project it works ok, but if I try to upload zip dir I got error and timeout exception
我的代码会产生超时异常
There is my code which produces timeout exception
let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = 10 // seconds configuration.timeoutIntervalForResource = 10 alamoFireManager = Alamofire.SessionManager(configuration: configuration) let fileData = FileManager.default.contents(atPath: filePath) alamoFireManager.upload(fileData, to: url, method: .post, headers: headers) .validate() .responseJSON {}这是可以正常工作的代码
And here is code which works fine
let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = 10 // seconds configuration.timeoutIntervalForResource = 10 alamoFireManager = Alamofire.SessionManager(configuration: configuration) let fileURL = Bundle.main.url(forResource: "MyImage", withExtension: "jpg") alamoFireManager.upload(fileURL, to: url, method: .post, headers: headers) .validate() .responseJSON {}我尝试传递Data()到上载请求,我也尝试传递对zip dit URL 的引用来上传请求,也尝试了 InputStream(URL:fileURL!)!但没有成功...
I tried to pass Data() to upload request also I tried pass reference to zip dit URL to upload request, also I tried InputStream(url: fileURL!)! but without success...
我在做什么错?如何将zip数据发送到服务器?
What am I doing wrong? how to send zip data to the server?
如果有任何问题可以随时询问!
if there is some question feel free to ask!
推荐答案最终,我发现了问题,服务器端不接受我的请求。另外,还有一些混乱,因为如果我尝试从项目中下载图像文件,则可以使用,但是如果从文档目录中选择了图像文件,则会出现问题。
Eventually, I found the issue, server side does not accept my request. Also, there is some confusion, because if I try to download an image file from my project it works, but if the file is selected from the document directory then there is an issue.
无论如何,如果有人遇到类似问题,请尝试检查您的服务器端。
Anyway if someone has a similar issue try to check your server side.
尝试检查您的请求是否发送到服务器并包含其中的内容。
Try to check if your request came to server and with content inside.
更多推荐
如何使用alamofire上传zip数据?
发布评论