[英]how to upload image file to FTP server in swift?
I am using Gold Raccoon in my swift project.我在我的 swift 项目中使用Gold Raccoon 。 My swift code builds and runs fine but when I check on the FTP Server there is no file.
我的 swift 代码构建并运行良好,但是当我检查 FTP 服务器时没有文件。 This is the code which I am using in viewDidload()
这是我在 viewDidload() 中使用的代码
var ftpRequest:GRRequestsManager!
var path = NSBundle.mainBundle().pathForResource("marker", ofType: ".png")
ftpRequest = GRRequestsManager(hostname: "192.x.x.x", user: "xx", password: "xxxx")
ftpRequest.addRequestForUploadFileAtLocalPath(path, toRemotePath: "/marker.png")
self.ftpRequest.startProcessingRequests()
Then I tried to check whether my file is successully uploaded or not by using delegate of GRRequestsManager ftpRequest.delegate = self
in viewDidload().然后我尝试通过在 viewDidload() 中使用 GRRequestsManager
ftpRequest.delegate = self
委托来检查我的文件是否成功上传。 and wrote these delegate functions in my swift class by conforming with GRRequestsManagerDelegate protocol.并通过符合GRRequestsManagerDelegate协议在我的 swift 类中编写了这些委托函数。
func requestsManager(requestsManager: GRRequestsManagerProtocol!, didCompleteUploadRequest request: GRDataExchangeRequestProtocol!) {
print("did Complete Upload Request")
}
func requestsManager(requestsManager: GRRequestsManagerProtocol!, didFailRequest request: GRRequestProtocol!, withError error: NSError!) {
print("did Fail Request")
}
when I compile its fine but when I run the code xcode gives me an error on this line ftpRequest.delegate = self
当我编译它很好但是当我运行代码时 xcode 在这一行
ftpRequest.delegate = self
给了我一个错误
unexpectedly found nil
意外发现 nil
I cannot upload my .png file to the FTP Server.我无法将我的 .png 文件上传到 FTP 服务器。 Allover the internet that I found is about Obj-C but NO swift code to do this.
我发现整个互联网都是关于 Obj-C 但没有快速代码来做到这一点。
Is there any swift way to do this?有什么快速的方法可以做到这一点吗?
Please guide me If I am doing wrong.如果我做错了,请指导我。 Or provide any running sample code that uploads the .png file to the FTP Server with Authentication(should require username and password)
或者提供任何正在运行的示例代码,将 .png 文件上传到带有身份验证的 FTP 服务器(应该需要用户名和密码)
NOTE : I am using Briding Header to use GoldRaccoon (as it is available only in Objective-C)注意:我使用 Briding Header 来使用GoldRaccoon (因为它仅在 Objective-C 中可用)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.