Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
amazon s3中的多部分上载在ios中不起作用_Ios_Objective C_Xcode_Amazon Web Services - Fatal编程技术网

amazon s3中的多部分上载在ios中不起作用

amazon s3中的多部分上载在ios中不起作用,ios,objective-c,xcode,amazon-web-services,Ios,Objective C,Xcode,Amazon Web Services,正在尝试将大于5 mb的文件上载到Amazon S3 -(void)multipartUpload:(NSData*)imageData inBucket:(NSString*)bucket forKey:(NSString*)key { NSLog(@"Coming"); bool using3G = ![self isWifiAvailable]; AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccess

正在尝试将大于5 mb的文件上载到Amazon S3

-(void)multipartUpload:(NSData*)imageData inBucket:(NSString*)bucket forKey:(NSString*)key
{
    NSLog(@"Coming");
    bool using3G = ![self isWifiAvailable];

    AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
    @try {
        NSLog(@"Coming111");
        [s3 createBucketWithName:bucket];

        S3InitiateMultipartUploadRequest *initReq = [[S3InitiateMultipartUploadRequest alloc] initWithKey:key inBucket:bucket];
        S3MultipartUpload *upload = [s3 initiateMultipartUpload:initReq].multipartUpload;
        S3CompleteMultipartUploadRequest *compReq = [[S3CompleteMultipartUploadRequest alloc] initWithMultipartUpload:upload];

        int numberOfParts = [self countParts:imageData];
        for ( int part = 0; part < numberOfParts; part++ ) {
            NSData *dataForPart = [self getPart:part fromData:imageData];

            // The S3UploadInputStream was deprecated after the release of iOS6.
            S3UploadInputStream *stream = [S3UploadInputStream inputStreamWithData:dataForPart];
            if ( using3G ) {
                // If connected via 3G "throttle" the stream.
                stream.delay = 0.2; // In seconds
                stream.packetSize = 16; // Number of 1K blocks
            }

            S3UploadPartRequest *upReq = [[S3UploadPartRequest alloc] initWithMultipartUpload:upload];
            upReq.partNumber = ( part + 1 );
            upReq.contentLength = [dataForPart length];
            upReq.stream = stream;

            S3UploadPartResponse *response = [s3 uploadPart:upReq];
            [compReq addPartWithPartNumber:( part + 1 ) withETag:response.etag];
        }

        [s3 completeMultipartUpload:compReq];
    }
    @catch ( AmazonServiceException *exception ) {
        NSLog( @"Multipart Upload Failed, Reason: %@", exception  );
    }
}

-(NSData*)getPart:(int)part fromData:(NSData*)fullData
{
    NSRange range;
    range.length = PART_SIZE;
    range.location = part * PART_SIZE;

    int maxByte = (part + 1) * PART_SIZE;
    if ( [fullData length] < maxByte ) {
        range.length = [fullData length] - range.location;
    }

    return [fullData subdataWithRange:range];
}

-(int)countParts:(NSData*)fullData
{
    int q = (int)([fullData length] / PART_SIZE);
    int r = (int)([fullData length] % PART_SIZE);

    return ( r == 0 ) ? q : q + 1;
}
-(void)多端口加载:(NSData*)包中的图像数据:(NSString*)桶叉键:(NSString*)键
{
NSLog(@“即将到来”);
bool使用3g=![self-isWifiAvailable];
AmazonS3Client*s3=[[AmazonS3Client alloc]initWithAccessKey:ACCESS\u KEY\u ID with secretKey:SECRET\u KEY];
@试一试{
NSLog(@“Coming111”);
[s3 createBucketWithName:bucket];
S3InitiateMultipartUploadRequest*initReq=[[S3InitiateMultipartUploadRequest alloc]initWithKey:key inBucket:bucket];
S3multipartPload*upload=[s3 initiateMultipartUpload:initReq].multipartPload;
S3CompleteMultipPartUploadRequest*compReq=[[S3CompleteMultipPartUploadRequest alloc]initWithMultipartPload:upload];
int numberOfParts=[self countParts:imageData];
对于(int part=0;part

不上传视频。请帮助我。

您可以分享您使用的AWS iOS SDK的版本以及收到的任何错误吗?您可能还想查看S3TransferManager,因为它将使用多部分上载处理较大的文件上载。