菜鸟教程小白 发表于 2022-12-11 18:54:10

ios - 应用程序在 swift 3 的 AWS S3 存储桶中上传图像时崩溃


                                            <p><p>在我的应用程序中,我正在尝试使用 AWS S3 上传图像。但是,当我从库中选择图像或捕获的图像时,在上传过程中我的应用程序崩溃了。 </p>

<pre><code>let path:NSString = (NSTemporaryDirectory() as NSString).appendingPathComponent(&#34;testImage.png&#34;) as NSString
let imageData:NSData = UIImagePNGRepresentation(image)! as NSData
imageData.write(toFile: path as String, atomically: true)
let url:NSURL = NSURL(fileURLWithPath: path as String)
let expression = AWSS3TransferUtilityUploadExpression()
expression.setValue(&#34;public-read&#34;, forRequestParameter: &#34;x-amz-acl&#34;)
expression.setValue(&#34;public-read&#34;, forRequestHeader: &#34;x-amz-acl&#34; )
let transferUtility = AWSS3TransferUtility.default()

transferUtility.uploadFile(url as URL!, bucket: bucketURL, key: myImageUploadKey , contentType: &#34;image/png&#34;, expression: expression, completionHandler: { (task, error) in

if error != nil{
print(error?.localizedDescription ?? &#34;error&#34;)
}else{
print(task.response ?? &#34;Response error&#34;)
}
})

expression.progressBlock = { (task: AWSS3TransferUtilityTask, progress: Progress) in
print(&#34;progress \(progress.fractionCompleted)&#34;)
}
</code></pre>

<p>应用程序在 let transferUtility = AWSS3TransferUtility.default() 处崩溃</p>

<p>所以请提出任何解决方案。将不胜感激。谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这个问题可能是由于 AWS S3 pod 更新而出现的。请检查最新的 pod。请查看 <a href="https://github.com/aws/aws-sdk-ios" rel="noreferrer noopener nofollow">https://github.com/aws/aws-sdk-ios</a> </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 应用程序在 swift 3 的 AWS S3 存储桶中上传图像时崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/42152318/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/42152318/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 应用程序在 swift 3 的 AWS S3 存储桶中上传图像时崩溃