简体   繁体   中英

Are there Low level Swift classes to upload files in AWS S3

Here is the same code in Java was wondering if they have a swift equivalent, which allows you to break up files into parts:

long partSize = 5 * 1024 * 1024;

        try {
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                                    .withRegion(clientRegion)
                                    .withCredentials(new ProfileCredentialsProvider())
                                    .build();

            List<PartETag> partETags = new ArrayList<PartETag>();


            InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(bucketName, keyName);
            InitiateMultipartUploadResult initResponse = s3Client.initiateMultipartUpload(initRequest);

            long filePosition = 0;
            for (int i = 1; filePosition < contentLength; i++) {
                partSize = Math.min(partSize, (contentLength - filePosition));


                UploadPartRequest uploadRequest = new UploadPartRequest()
                        .withBucketName(bucketName)
                        .withKey(keyName)
                        .withUploadId(initResponse.getUploadId())
                        .withPartNumber(i)
                        .withFileOffset(filePosition)
                        .withFile(file)
                        .withPartSize(partSize);

                UploadPartResult uploadResult = s3Client.uploadPart(uploadRequest);
                partETags.add(uploadResult.getPartETag());

                filePosition += partSize;
            }


            CompleteMultipartUploadRequest compRequest = new CompleteMultipartUploadRequest(bucketName, keyName,
                    initResponse.getUploadId(), partETags);
            s3Client.completeMultipartUpload(compRequest);
        }

You can use the AWSS3 client from AWSiOSSDKv2 here: https://github.com/aws/aws-sdk-ios

The request which you are looking for is this: https://github.com/aws/aws-sdk-ios/blob/master/AWSS3/AWSS3Model.h#L6618 and can be used be invoked via this API: https://github.com/aws/aws-sdk-ios/blob/master/AWSS3/AWSS3Service.h#L1994

Thanks, Rohan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM