草庐IT

ios - 停止/取消在 AWS S3 上上传

coder 2023-07-16 原文

我正在使用 AWSLocal 内容上传方法来上传文件。我需要从另一个屏幕取消上传。

这是上传功能:

private func uploadLocalContent(localContent: AWSLocalContent) {
    localContent.uploadWithPinOnCompletion(false, progressBlock: {[weak self](content: AWSLocalContent?, progress: NSProgress?) -> Void in
        guard let strongSelf = self else { return }
        dispatch_async(dispatch_get_main_queue()) {
            // Update the upload UI if it is a new upload and the table is not yet updated
            if(strongSelf.tableView.numberOfRowsInSection(0) == 0 || strongSelf.tableView.numberOfRowsInSection(0) < strongSelf.manager.uploadingContents.count) {
                strongSelf.updateUploadUI()
            } else {

                for uploadContent in strongSelf.manager.uploadingContents {
                    if uploadContent.key == content?.key {
                        let index = strongSelf.manager.uploadingContents.indexOf(uploadContent)!
                        let indexPath = NSIndexPath(forRow: index, inSection: 0)
                        strongSelf.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .None)
                    }
                }
            }
        }
        }, completionHandler: {[weak self](content: AWSContent?, error: NSError?) -> Void in
            guard let strongSelf = self else { return }
            strongSelf.updateUploadUI()
            if let error = error {
                print("Failed to upload an object. \(error)")
                strongSelf.showSimpleAlertWithTitle("Error", message: "Failed to upload an object.", cancelButtonTitle: "OK")
            } else {
                strongSelf.refreshContents()
            }
        })
    updateUploadUI()
}

最佳答案

不幸的是,当从 AWSLocalContent 调用时无法取消上传,因为无法访问 AWTask

查看 AWSS3TransferManager(http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSS3TransferManager.html#//api/name/upload :),它为每个操作创建一个 AWTask,它可以是上传或下载,也可以是取消/暂停/恢复。此外,您还可以从 AWSS3TransferManager 获得方便的方法,它可以立即取消/暂停/恢复所有任务。

您必须创建正在上传的 AWTask,将其保存在其他屏幕可访问的某个位置,然后您就可以取消它。

关于ios - 停止/取消在 AWS S3 上上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41588045/

有关ios - 停止/取消在 AWS S3 上上传的更多相关文章

  1. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  2. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  3. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  4. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

  5. ruby - 使用 Ruby Daemons gem 检测停止 - 2

    我正在使用rubydaemongem。想知道如何向停止操作添加一些额外的步骤?希望我能检测到停止被调用,并向其添加一些额外的代码。任何人都知道我如何才能做到这一点? 最佳答案 查看守护程序gem代码,它似乎没有用于此目的的明显扩展点。但是,我想知道(在守护进程中)您是否可以捕获守护进程在发生“停止”时发送的KILL/TERM信号...?trap("TERM")do#executeyourextracodehereend或者你可以安装一个at_exit钩子(Hook):-at_exitdo#executeyourextracodehe

  6. ruby - 如何停止 jekyll 本地服务器 - 2

    我刚刚在本地设置了我的第一个Jekyll项目。我已经让服务器运行,但我忘了使用自动标志。所以现在我想停止服务器并使用标志重新启动。但是,在我启动服务器后的命令行中,我没有得到新的提示,所以我无法输入任何新命令。我不太习惯命令行,所以我真的很感激知道我应该做什么!我正在使用MacOSX和terminal.app,如果有区别的话! 最佳答案 psaux|grepjekyll|awk'{print$2}'|xargskill-9 关于ruby-如何停止jekyll本地服务器,我们在StackO

  7. ruby-on-rails - 取消 Rails 数据库连接 - 2

    我正在编写一个将服务器端事件与ActionController::Live结合使用的应用程序。它正在使用puma应用程序服务器。当用户连接等待来自Redis的消息时,消息Controller中的方法保持事件状态。问题是我不想通过这种方法连接到Postgres。我在六个选项卡中打开应用程序后,它有超过五个连接,由config/database.yml文件中的池大小定义,应用程序崩溃。无论如何,在调用该方法时是否可以告诉我的应用它不需要连接到数据库,因为其中没有ActiveRecord查询调用? 最佳答案 一种可能的方法是使用中间件。设

  8. ruby - 为 IO::popen 拯救 "command not found" - 2

    当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

  9. ruby - IO::EAGAINWaitReadable:资源暂时不可用 - 读取会阻塞 - 2

    当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab

  10. ruby-on-rails - EC2 实例在负载均衡器中停止服务 - 2

    我有一个EC2实例正在运行。我有一个负载均衡器,它与EC2实例相关联。PingTarget:HTTP:3001/healthCheckTimeout:5secondsInterval:24secondsUnhealthythreshold:2Healthythreshold:10现在该实例显示为OutofService。我什至尝试更改监听端口等等。一切正常,直到重新启动我的EC2实例。任何帮助将不胜感激。仅供引用:我有一个在端口3001上运行的Rails应用程序,我有一个用于HTTP:80(loadbalancer)到HTTP:3001的监听器。我还在终端中通过ssh检查了正在运行的应

随机推荐