3 | #else
4 | #ifndef FOUNDATION_EXPORT
5 | #if defined(__cplusplus)
6 | #define FOUNDATION_EXPORT extern "C"
7 | #else
8 | #define FOUNDATION_EXPORT extern
9 | #endif
10 | #endif
11 | #endif
12 |
13 |
14 | FOUNDATION_EXPORT double Pods_AmazonS3UploadVersionNumber;
15 | FOUNDATION_EXPORT const unsigned char Pods_AmazonS3UploadVersionString[];
16 |
17 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-AmazonS3Upload/Pods-AmazonS3Upload.debug.xcconfig:
--------------------------------------------------------------------------------
1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/AWSCore" "$PODS_CONFIGURATION_BUILD_DIR/AWSS3"
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/AWSCore/AWSCore.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/AWSS3/AWSS3.framework/Headers"
5 | OTHER_LDFLAGS = $(inherited) -framework "AWSCore" -framework "AWSS3"
6 | PODS_BUILD_DIR = $BUILD_DIR
7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
9 | PODS_ROOT = ${SRCROOT}/Pods
10 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-AmazonS3Upload/Pods-AmazonS3Upload.modulemap:
--------------------------------------------------------------------------------
1 | framework module Pods_AmazonS3Upload {
2 | umbrella header "Pods-AmazonS3Upload-umbrella.h"
3 |
4 | export *
5 | module * { export * }
6 | }
7 |
--------------------------------------------------------------------------------
/Pods/Target Support Files/Pods-AmazonS3Upload/Pods-AmazonS3Upload.release.xcconfig:
--------------------------------------------------------------------------------
1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "$PODS_CONFIGURATION_BUILD_DIR/AWSCore" "$PODS_CONFIGURATION_BUILD_DIR/AWSS3"
2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks'
4 | OTHER_CFLAGS = $(inherited) -iquote "$PODS_CONFIGURATION_BUILD_DIR/AWSCore/AWSCore.framework/Headers" -iquote "$PODS_CONFIGURATION_BUILD_DIR/AWSS3/AWSS3.framework/Headers"
5 | OTHER_LDFLAGS = $(inherited) -framework "AWSCore" -framework "AWSS3"
6 | PODS_BUILD_DIR = $BUILD_DIR
7 | PODS_CONFIGURATION_BUILD_DIR = $PODS_BUILD_DIR/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
8 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
9 | PODS_ROOT = ${SRCROOT}/Pods
10 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # How to upload a file to Amazon S3 using Swift
2 |
3 | I would like to share a simple tutorial how to upload a to Amazon S3 in iOS using Swift. Let’s go.
4 |
5 | 
6 |
7 | We need to add Amazon S3 framework to your project.
8 | In this example I will do this with helping Cocoapods.
9 |
10 | Create a Podfile:
11 |
12 |
13 | platform :ios, '8.0'
14 | inhibit_all_warnings!
15 | use_frameworks!
16 | target 'AmazonS3Upload' do
17 | pod 'AWSS3'
18 | end
19 |
20 |
21 | Run the next command from Terminal:
22 |
23 |
24 | pod install
25 |
26 |
27 | Open the generated workspace. And after that we can implement uploading of files using frameworks from Pods.
28 |
29 | We need to import 2 modules:
30 |
31 |
32 | import AWSS3
33 | import AWSCore
34 |
35 |
36 | Set up a AWS configuration using your credentials. For example:
37 |
38 |
39 | let accessKey = "..."
40 | let secretKey = "..."
41 | let credentialsProvider = AWSStaticCredentialsProvider(accessKey: accessKey, secretKey: secretKey)
42 | let configuration = AWSServiceConfiguration(region: AWSRegionType.usEast1, credentialsProvider: credentialsProvider)
43 | AWSServiceManager.default().defaultServiceConfiguration = configuration
44 |
45 |
46 | Create an upload request:
47 |
48 |
49 | let url = ...URL to your file...
50 | let remoteName = "Name of uploaded file"
51 | let S3BucketName = "Name of your bucket on Amazon S3"
52 | let uploadRequest = AWSS3TransferManagerUploadRequest()!
53 | uploadRequest.body = url
54 | uploadRequest.key = remoteName
55 | uploadRequest.bucket = S3BucketName
56 | uploadRequest.contentType = "image/jpeg"
57 | uploadRequest.acl = .publicRead
58 |
59 |
60 | And upload using AWSS3TransferManager.
61 |
62 |
63 | let transferManager = AWSS3TransferManager.default()
64 | transferManager?.upload(uploadRequest).continue({ (task: AWSTask) -> Any? in
65 | if let error = task.error {
66 | print("Upload failed with error: (\(error.localizedDescription))")
67 | }
68 | if let exception = task.exception {
69 | print("Upload failed with exception (\(exception))")
70 | }
71 | if task.result != nil {
72 | let url = AWSS3.default().configuration.endpoint.url
73 | let publicURL = url?.appendingPathComponent(uploadRequest.bucket!).appendingPathComponent(uploadRequest.key!)
74 | print("Uploaded to:\(publicURL)")
75 | }
76 | return nil
77 | })
78 |
79 |
--------------------------------------------------------------------------------
/img/img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/maximbilan/Swift-Amazon-S3-Uploading-Tutorial/b0401281f206444ad36b2566894f6cfa2d7e761e/img/img1.png
--------------------------------------------------------------------------------