mercredi 31 décembre 2014

Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?

I tried both SDK version V1 and V2. I have application in which I am posting user's photo/video on s3. When the device's timezone is not set to automatic,many times uploading fails because of timezone difference. I am not able to catch this error or exception consistently. didFailWithError never get called for timezone difference,I have to catch it in didCompleteWithResponse.


I used below code for 1.7.1 SDK.



[AmazonLogger verboseLogging];
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:AWS_AccessKey withSecretKey:AWS_SecretKey];
s3.endpoint=[AmazonEndpoints s3Endpoint:US_EAST_1];

@try
{

por = [[S3PutObjectRequest alloc] initWithKey:[aStrAWSPath lastPathComponent] inBucket:aStrFolder];
por.contentType = aStrType;
por.data = aDataToPost;
por.delegate=self;
[por setCannedACL:[S3CannedACL publicReadWrite]];
[s3 putObject:por];
aWSTotalBytesWritten = 0.0;
}
@catch (AmazonServiceException *exception)
{
NSLog(@"%@",exception.description);
}
@catch (AmazonClientException *exception)
{
NSLog(@"%@",exception.description);
}

-(void)request:(AmazonServiceRequest *)request didCompleteWithResponse:(AmazonServiceResponse *)response
{
if(response.exception==nil)
{
//Success
}
else
{
if([response.exception isKindOfClass:[AmazonServiceException class]])
{
AmazonServiceException *aServiceExceptionObj=(AmazonServiceException *)response.exception;
if([aServiceExceptionObj.errorCode isEqualToString:@"RequestTimeTooSkewed"])
{
//Please check your date&time settings.It should be set to automatically.
}
}
}
-(void)request:(AmazonServiceRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"AWSError : %@", error.description);
}


In AWSiOSSDKv2,I used below code,



AWSServiceConfiguration *aConfigObj=[AWSServiceConfiguration configurationWithRegion:AWSRegionUSEast1 credentialsProvider:CustomCredentialsProviderObj];
AWSS3TransferManager *transferManager = [[AWSS3TransferManager alloc] initWithConfiguration:aConfigObj identifier:@"testUplaod"];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = @"testsdkv2/testsdkv2internal";
uploadRequest.key = [NSString stringWithFormat:@"%d.jpg",(int)[[NSDate date]timeIntervalSince1970]];
NSURL *aUrlObj=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]];
uploadRequest.body = aUrlObj;
uploadRequest.ACL=AWSS3BucketCannedACLPublicReadWrite;
uploadRequest.contentType=@"image/jpeg";

[[transferManager upload:uploadRequest] continueWithBlock:^id(BFTask *task) {


if (task.error)
{
//Not uploaded
}

if (task.result)
{
// The file uploaded successfully.
}

return nil;
}];




Aucun commentaire:

Enregistrer un commentaire