菜鸟教程小白 发表于 2022-12-12 09:56:39

ios - 将文件从 iOS 上传到 Amazon S3


                                            <p><p>我正在尝试将使用 UIImagePickerController 录制的短视频上传到 Amazon S3。我正在关注看似简单的 Amazon 示例代码,但我的文件没有出现在我的存储桶中。</p>

<p>我正在记录委托(delegate)方法,奇怪的是 totalBytesWritten 小于 totalBytesExpected。</p>

<p>这是我的代码:</p>

<pre><code>AmazonS3Client *s3 = [ initWithAccessKey:AWS_ACCESS_KEY withSecretKey:AWS_SECRET_KEY];
S3PutObjectRequest *por = [ initWithKey:@&#34;test.mov&#34; inBucket:@&#34;mybucket&#34;];
por.contentType = @&#34;video/quicktime&#34;;
NSData *videoData = ;
por.data = videoData;
por.delegate = self;
;
</code></pre>

<p>获得任何响应的唯一委托(delegate)方法是报告字节。其他人没有被调用。</p>

<p><strong>更新</strong></p>

<p>如果文件非常小,它实际上可以工作。一个 110000 字节的文件上传正常。它每次都停在 196608 字节处。如果文件小于它就会上传。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>所以这里有两个问题。由于文件很大,我切换到使用 <code>S3TransferManager</code>
我还设置了至关重要的端点。最终代码为:</p>

<pre><code>AmazonS3Client *s3 = [ initWithAccessKey:AWS_ACCESS_KEY withSecretKey:AWS_SECRET_KEY];
s3.endpoint = ;
S3TransferManager *transferManager = ;
transferManager.s3 = s3;
transferManager.delegate = self;
s3.endpoint = ;
NSData *videoData = ;
;
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 将文件从 iOS 上传到 Amazon S3,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/23725160/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/23725160/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 将文件从 iOS 上传到 Amazon S3