文档中心 > 简单上传
简单上传

最近更新时间:2022-09-29

简单上传指的是使用OSS API中的PutObject方法上传单个文件(Object)。

以下代码用于上传文件:

let fileURL = NSURL.fileURL(withPath:"your file path") as AnyObject
// let dataBody:NSData? = "wrwrwrwrwrw".data(using: .utf8) as NSData?;
let uploadRequest = AWSS3PutObjectRequest.init()
uploadRequest?.body = fileURL
uploadRequest?.key = "mytest.png"
uploadRequest?.bucket = S3BucketName

s3.putObject(uploadRequest!).continueWith(executor: AWSExecutor.mainThread(), block:  { (task:AWSTask) -> Any? in
   if let error = task.error {
       print("Upload failed with error: (\(error))")
   } else {
       print("Upload completed!")
   }
   return nil
})