Reputation: 1538
I am trying to upload video to the S3 server with temporary credential access. Its ~3Mb file. I tried with AWS S3 Sample examples . I don't want to use AWS Cognito. So now how to upload the video .
Thanks
Upvotes: 0
Views: 118
Reputation: 13600
I have created a sample code to upload text file on amazon
- (void)upload
{
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// *** Set background task accordingly ***
[appDel setApplicationObj:[UIApplication sharedApplication]];
[appDel setBgTask:[[appDel applicationObj] beginBackgroundTaskWithExpirationHandler:^{
[[appDel applicationObj] endBackgroundTask:[APP_DEL bgTask]];
[appDel setBgTask:UIBackgroundTaskInvalid];
}]];
// *** Begin file upload task to Amazon ***
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
// File upload task .
@try {
// *** Initialize AmazonS3Client object using AccessKey and SecretKey ***
AmazonS3Client *objAmazonS3 = [[AmazonS3Client alloc] initWithAccessKey:@"<Access Key>" withSecretKey:@"<Secret Key>"];
objAmazonS3.endpoint = [AmazonEndpoints s3Endpoint:US_EAST_1];
// *** Initialize S3PutObjectRequest with filename & bucket in which to drop it. ***
S3PutObjectRequest *objS3PutRequest = [[S3PutObjectRequest alloc] initWithKey:@"MyFile.txt" inBucket:@"<Bucket Name>"];
// *** Set content type according to your file type, here its plain text ****
[objS3PutRequest setContentType:@"text/plain"];
// *** set NSData of your File, here i am converting String into NSData ***
NSData *data = [@"This is my sample text" dataUsingEncoding:NSUTF8StringEncoding];
[objS3PutRequest setData:data];
// *** Its optional ***
[objS3PutRequest setRequestTag:@"fileUpload"];
// *** Start upload task by putting request ***
[objAmazonS3 putObject:objS3PutRequest];
// *** Register upload callback, when it finishes upload it will invoke following method ***
[self performSelectorOnMainThread:@selector(fileUploadCallback)
withObject:nil
waitUntilDone:NO];
}
@catch (AmazonClientException *exception)
{
NSLog(@"File Upload Failed, Reason: %@", exception);
}
});
}
- (void)fileUploadCallback
{
NSLog(@"Upload complete.");
}
Upvotes: 0
Reputation: 1428
You have to write some code to use Presigned PUT object - http://docs.aws.amazon.com/AmazonS3/latest/dev/PresignedUrlUploadObject.html
Upvotes: 1