Swift3 如何在swift 3.0中使用Backhandle上传图像

Swift3 如何在swift 3.0中使用Backhandle上传图像,swift3,uiimagepickercontroller,backendless,Swift3,Uiimagepickercontroller,Backendless,我正在致力于swift 3.0 uisng。我对这个概念还不熟悉。我正在上传使用UIImagePickerController从手机图库中选择的图像。在后面,我正在使用RESTAPI。我使用以下代码上传图像 public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) { let image

我正在致力于swift 3.0 uisng。我对这个概念还不熟悉。我正在上传使用UIImagePickerController从手机图库中选择的图像。在后面,我正在使用RESTAPI。我使用以下代码上传图像

 public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
    {
        let image = info[UIImagePickerControllerOriginalImage] as? UIImage
        self.uploadButton.isHidden = true
        myImageView.contentMode = .scaleAspectFit
       myImageView.image = image


        let imageUrl          = info[UIImagePickerControllerReferenceURL] as! NSURL
        let imageName         = imageUrl.lastPathComponent
        let documentDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
        let photoURL          = NSURL(fileURLWithPath: documentDirectory)
        let localPath         = photoURL.appendingPathComponent(imageName!)

        print(localPath!)


        let imageurl = info[UIImagePickerControllerReferenceURL] as? NSURL
        let imagename = imageurl?.lastPathComponent
        print(imagename!)

         //https://api.backendless.com/<application id>/<version name>/files/<path>/<file name>

        Alamofire.request(“https://api.backendless.com/66B90F83-A813-84CF-FF9D-4A01AC28E100/v1/files/ + "\(localPath!)/\(imagename!)", method: .post, parameters: nil, encoding: JSONEncoding.default, headers: HeadersClass.allHeaders.headers).responseJSON { response in
            debugPrint(response)
        }

        imagePicker.dismiss(animated: true, completion: nil)

    }
public func imagePickerController(picker:UIImagePickerController,didFinishPickingMediaWithInfo:[字符串:任意])
{
将image=info[UIImagePickerControllerOriginalImage]设为?UIImage
self.uploadButton.ishiden=true
myImageView.contentMode=.ScaleSpectFit
myImageView.image=image
将imageUrl=info[UIImagePickerControllerReferenceURL]设为!NSURL
让imageName=imageUrl.lastPathComponent
让documentDirectory=NSSearchPathForDirectoriesInDomains(.documentDirectory、.userDomainMask,true)。首先!
让photoURL=NSURL(fileURLWithPath:documentDirectory)
让localPath=photoURL.appendingPathComponent(imageName!)
打印(本地路径!)
将imageurl=info[UIImagePickerControllerReferenceURL]设为?NSURL
让imagename=imageurl?.lastPathComponent
打印(imagename!)
//https://api.backendless.com///files//
Alamofire.request(“https://api.backendless.com/66B90F83-A813-84CF-FF9D-4A01AC28E100/v1/files/ +“\(localPath!)/\(imagename!)”,方法:.post,参数:nil,编码:JSONEncoding.default,头:HeadersClass.allHeaders.headers.responseJSON{response in
调试打印(响应)
}
imagePicker.Disclose(动画:true,完成:nil)
}
但我得到的是“状态代码错误=400”

谁能告诉我我在这里犯了什么错误。
提前谢谢。

从第一步开始,你就完全错了。 您发出的请求url是返回url,当您成功上载文件时,BackEnding服务将返回给您

关于回溯服务,您需要实现下面列出的功能:

// Upload data block identified as 'content' to the specified path.
// If the server returns an error, it is delivered through
// the 'responder' object
func upload(_ path: String,
            content content: NSData,
            responder responder: IResponder!) -> Void

// Upload data block identified as 'content' to the specified path.
// If the file already exists on the server, overwrite if the
// 'overwrite' argument is set to YES/TRUE.
// If the server returns an error, it is delivered through
// the 'responder' object
func upload(_ path: String,
            content content: NSData,
            overwrite overwrite: Bool,
            responder responder: IResponder!) -> Void

// Upload data block identified as 'content' to the specified path.
// If the server returns an error, it is delivered through
// the 'error' block-based callback
func upload(_ path: String,
            content content: NSData,
            response responseBlock: ((BackendlessFile!) -> Void)!,
            error errorBlock: ((Fault!) -> Void)!) -> Void

// Upload data block identified as 'content' to the specified path.
// If the file already exists on the server, overwrite if the
// 'overwrite' argument is set to YES/TRUE.
// If the server returns an error, it is delivered through
// the 'error' block-based callback
func upload(_ path: String,
            content content: NSData,
            overwrite overwrite: Bool,
            response responseBlock: ((BackendlessFile!) -> Void)!,
            error errorBlock: ((Fault!) -> Void)!) -> Void

更多详细信息,您可以阅读他们的文档。

为什么您不使用他们的库?我使用该Api仅用于获取400状态码错误否,您试图通过alamofire发送,请求不存在的地址,后台服务器如何知道您的文件本地路径?使用他们所做的上传文件如果我想使用应用程序动态上传图像,你有一节要讲。我使用了“上传功能”,但是我怎么能看到我发送的图像呢?