I am uploading video to Amazon S3 from iphone application. Earlier it was uploading fine but now all of a sudden it has stopped uploading the video and crashes the app. Below is the code for video upload
if(![ACCESS_KEY_ID isEqualToString:#"CHANGE ME"]
&& self.s3 == nil)
{
// Initial the S3 Client.
self.s3 = [[[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY] autorelease];
self.s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
}
NSString *videoName =[NSString stringWithFormat:#"%#",titleTextField.text];
NSString *trimmedString = [videoName stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];
NSLog(#"name %#",trimmedString);
S3PutObjectRequest *por = [[[S3PutObjectRequest alloc] initWithKey:trimmedString
inBucket:[Constants pictureBucket]] autorelease];
por.contentType = #"movie/mp4";
por.data= videoData;
S3PutObjectResponse *putObjectResponse = [self.s3 putObject:por];
Here is the crash log
Terminating app due to uncaught exception 'AmazonServiceException', reason: '(null)' * First throw call stack: (0x2f370f53 0x399db6af 0xb6119 0xc39b3 0xc2f4d 0x533b9 0x5366f 0x2fd53e27 0x3a002c1d 0x3a002b8f 0x3a000c90) libc++abi.dylib: terminating with uncaught exception of type AmazonServiceException
Try setting the content length field and locally declaring the S3 client:
AmazonS3Client *s3 = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY]; //auto release deprecated, and not necessary with local declaration
s3.endpoint = [AmazonEndpoints s3Endpoint:US_WEST_2];
//post full video
por = [[S3PutObjectRequest alloc] initWithKey:generatedString inBucket:#"dormpicbucket"];
por.contentType = #"video/mp4";
por.data = capturedMovie;
por.delegate = self;
[por setDelegate:self];
por.contentLength = [capturedMovie length];
[s3 putObject:por];
Also make sure to debug this: [Constants pictureBucket] because it looks like youre using the sample/tutorial code from aws docs almost explicitly lol.
Related
I am an iOS developer using Amazon S3 to upload and download the data. I successfully uploaded many image files, but when I am trying to download those all files, I am not able to save data or file on targeted path of S3GetObjectRequest. I am requesting object through the S3TransferManager.
Below is my code
- (void)listObjects:(id)sender {
self.collection = [[NSMutableArray alloc] init];
s3Client = [[AmazonS3Client alloc] initWithAccessKey:ACCESS_KEY_ID withSecretKey:SECRET_KEY];
#try {
S3ListObjectsRequest *req = [[S3ListObjectsRequest alloc] initWithName:AMAZON_BUCKET_NAME];
req.prefix = #"arvinds/8/";
//req.prefix = [NSString stringWithFormat:#"%#", self.appUser.userEmail];
S3ListObjectsResponse *resp = [s3Client listObjects:req];
NSMutableArray* objectSummaries = resp.listObjectsResult.objectSummaries;
for (int x = 0; x < [objectSummaries count]; x++) {
NSLog(#"objectSummaries: %#",[objectSummaries objectAtIndex:x]);
S3ObjectSummary *s3Object = [objectSummaries objectAtIndex:x];
NSString *downloadingFilePath = [[NSTemporaryDirectory() stringByAppendingPathComponent:#"download"] stringByAppendingPathComponent:s3Object.key];
NSURL *downloadingFileURL = [NSURL fileURLWithPath:downloadingFilePath];
NSLog(#"downloadingFilePath--- %#",downloadingFilePath);
if ([[NSFileManager defaultManager] fileExistsAtPath:downloadingFilePath]) {
[self.collection addObject:downloadingFileURL];
} else {
[self.collection addObject:downloadingFileURL];
S3GetObjectRequest *getObj = [[S3GetObjectRequest new] initWithKey:s3Object.key withBucket:AMAZON_BUCKET_NAME];
getObj.targetFilePath = downloadingFilePath;
getObj.delegate = self;
[self download:getObj];// Start downloding image and write in default folder
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.GalleryCollectionView reloadData];
//[self downloadAllRequestObject];
});
}
#catch (NSException *exception) {
NSLog(#"Cannot list S3 %#",exception);
}
}
// Above code is for access all the objects stored on Amazon S3 server.
// Below code is for S3TransferManager request
- (void)download:(S3GetObjectRequest *)downloadRequest {
S3TransferManager *transferManager = [S3TransferManager new];
transferManager.s3 = s3Client;
transferManager.delegate = self;
[transferManager download:downloadRequest];
}
When executing this, it is not saving data on the target path.
- download: is an asynchronous method and returns immediately. Since you are not retaining a strong reference to an instance of S3TransferManager, it can be released before the download completes. You need to keep a strong reference to transferManager.
Please note that you are using a deprecated version of the AWS SDK. It may be worthwhile to migrate to the version 2 of the AWS Mobile SDK for iOS. With the latest version of the SDK, you do not need to worry about the memory retention issue you are encountering.
I am trying to parse the contents of a downloaded CSV File. The file is stored in a folder in Local Documents Directory.
Filepath: /Users/xyz/Library/Developer/CoreSimulator/Devices/C04089B6-4B9F-4F3A-A7C4-82225024CBE4/data/Containers/Data/Application/7412C7C6-71C7-47FE-810B-965116A6071C/Documents/rndftp/99999920150415152101.csv
I am using this method to create a NSInputStream :
- (instancetype)initWithContentsOfDelimitedURL:(NSURL *)URL delimiter:(unichar)delimiter {
NSInputStream *stream = [NSInputStream inputStreamWithURL:URL];
return [self initWithInputStream:stream usedEncoding:NULL delimiter:delimiter];
}
Here, URL is [NSURL URLWithString: filepath] but for this, stream is coming as nil.
Thus, it is crashing here:
CHCSVParser *parser = [[CHCSVParser alloc] initWithContentsOfCSVURL:[NSURL URLWithString:filePath]];
[parser parse];
NSArray *latestFileComponentsArray = [NSArray arrayWithContentsOfCSVURL:[NSURL URLWithString:filePath]];
with the error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: stream'
What can be the possible reason for the same? I am using CHCSVParser open source for parsing the csv file.
My bad, There is a small caveat here: If the file is locally downloaded, we specify the URL as fileURLwithPath: and not URLWithString: , so the code that is causing the error can be rectified as:
CHCSVParser *parser = [[CHCSVParser alloc] initWithContentsOfCSVURL:[NSURL fileURLWithPath:filePath]];
[parser parse];
NSArray *latestFileComponentsArray = [NSArray arrayWithContentsOfCSVURL:[NSURL fileURLWithPath:filePath]];
I am trying to play audio and switch views with the same button..
- (IBAction)yourbuttonClicked:(UIButton *)sender
{
//start a background sound
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"tap2" ofType: #"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:soundFilePath ];
myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
myAudioPlayer.numberOfLoops = -1; //infinite loop
[myAudioPlayer play];
//for Switch view
ViewController *nextView = [[ViewController alloc] initWithNibName:#"ViewController2"
bundle: Nil];
[self.navigationController pushViewController:nextView animated:YES];
}
2014-03-02 19:07:46.817 Balloon Tap[847:70b] * Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '* -[NSURL initFileURLWithPath:]: nil string
parameter'
When I launch my simulator and click on the play button that performs the action it crashes and in my log it comes up with this error above..
How do I go about fixing this and editing my code?
It appears soundFilePath is Nil
Try this
NSURL *url = [NSURL fileURLWithPath:stringPath];
This removes the alloc, which may cause you some issues here. Also I'm sure you've checked, but is there an issue with the filename? Does it actually exist in your bundle? I.e is it being compiled with the rest of your code? Make sure that you add that file to your project, and it appears in a "Copy Bundle Resources" build phase in your executable's target in Xcode.
iOS beginner, I am trying to upload videos on youtube using the google objective c api.
In most cases, it just works. Videos can be uploaded and my callback receives errors if they occur.
But if I turn off the internet connection on the device, the callback is never called. (even though it is called for other types of errors, like incorrect title or incorrect tags)
My personal guess it that while I have set a callback for GTLServiceYouTube, I haven't explicitly set one for GTMOAuth2Authentication, hence the absence of a call. But I am not sure how to set one and found nothing about it anywhere.
Note that in my situation, I really need my users to be able to upload a video without having to enter their credentials, hence the manual initialization of the GTMOAuth2Authentication.
Here is my code, please tell me if I am doing something wrong and how I could fix it.
NSString *clientID = #"185815387242-hqo2d4e06j4hk4f02t5gvn7jcifakdvr.apps.googleusercontent.com";
NSString *clientSecret = #"2LKi7orHyphJXXXXXXXXXXXX";
NSURL *tokenURL = [NSURL URLWithString:#"https://accounts.google.com/o/oauth2/token"];
NSString *redirectURI = #"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:kGTMOAuth2ServiceProviderGoogle
tokenURL:tokenURL
redirectURI:redirectURI
clientID:clientID
clientSecret:clientSecret];
[auth setKeysForResponseString:#"email=annonce-video-i-6620%40pages.plusgoogle.com&isVerified=1&refresh_token=1%2FFFo5rlNs51u9g2TpCIE2oji_ACvDPc0XXXXXXXXXXXX&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email&serviceProvider=Google&userID=107586507912247324352"];
//////////////////////////////////////////////////
GTLServiceYouTube *youTubeService = [[GTLServiceYouTube alloc] init];
// Have the service object set tickets to fetch consecutive pages
// of the feed so we do not need to manually fetch them.
youTubeService.shouldFetchNextPages = YES;
// Have the service object set tickets to retry temporary error conditions
// automatically.
youTubeService.retryEnabled = YES;
youTubeService.authorizer = auth;
// Status.
GTLYouTubeVideoStatus *status = [GTLYouTubeVideoStatus object];
// Snippet.
GTLYouTubeVideoSnippet *snippet = [GTLYouTubeVideoSnippet object];
snippet.title = #"TITLE";
NSString *desc = #"DESC";
if ([desc length] > 0) {
snippet.descriptionProperty = desc;
}
NSString *tagsStr = #"TAGS";
if ([tagsStr length] > 0) {
snippet.tags = [tagsStr componentsSeparatedByString:#","];
}
GTLYouTubeVideo *video = [GTLYouTubeVideo object];
video.status = status;
video.snippet = snippet;
// Get a file handle for the upload data.
NSString *path = #"AVALIDPATH";
NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
if (fileHandle) {
NSString *mimeType = #"video/mp4";
GTLUploadParameters *uploadParameters =
[GTLUploadParameters uploadParametersWithFileHandle:fileHandle
MIMEType:mimeType];
uploadParameters.uploadLocationURL = nil;
GTLQueryYouTube *query = [GTLQueryYouTube queryForVideosInsertWithObject:video
part:#"snippet,status"
uploadParameters:uploadParameters];
GTLServiceYouTube *service = youTubeService;
[service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLYouTubeVideo *uploadedVideo,
NSError *error) {
//NEVER CALLED WHEN THE DEVICE IS IN AIRPLANE MODE
NSLog(#"And call me maybe.");
}];
I have traced back the absence of call to GTMHTTPFetcher line 969
#synchronized(self) {
target = [[delegate_ retain] autorelease];
sel = finishedSel_;
#if NS_BLOCKS_AVAILABLE
block = [[completionBlock_ retain] autorelease];
#endif
}
The synchronized block is called twice, once to call the GTMOAuth2Authentication callback, and a second time to call... Well... nil
A bug in retry handling on uploads was recently fixed in the library. Try updating your Google API library sources.
I cannot seem to get this link:
https://api.soundcloud.com/tracks/54507667/stream
to work with the AVAudioPlayer. I have tested it in a Souncloud API started project and it seems to work just fine, however, when I try to implement it on my own it doesn't seem to work.
The error I get:
unrecognized selector sent to instance 0x9245d40
2013-01-04 17:56:04.699 CollectionViewTest[17023:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString absoluteURL]: unrecognized selector sent to instance 0x9245d40'
* First throw call stack:.....
The code:
NSURL *streamURL = [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil];
NSLog(streamURL);
NSURLRequest *request = [NSURLRequest requestWithURL:streamURL];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(#"test:");
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
NSLog(#"test:2");
The streamURL prints as expected, and then the program crashes.
the tests are not printed.
When everything else is commented out, and the NSURLRequest is left, it still crashes.
When I comment the whole block of code out, everything compiles and runs.
I now have attempted this:
NSData *_objectData = [NSData dataWithContentsOfURL:streamURL];
NSError *error;
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:_objectData error:&error];
audioPlayer.numberOfLoops = 0;
audioPlayer.volume = 1.0f;
[audioPlayer prepareToPlay];
if (audioPlayer == nil)
NSLog(#"%#", [error description]);
else
[audioPlayer play];
This also returns the length error, I am at a loss on what could be causing this...
2013-01-05 13:46:16.536 CollectionViewTest[28224:c07] -[NSURL length]: unrecognized selector sent to instance 0x928a470
2013-01-05 13:46:16.546 CollectionViewTest[28224:c07] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x928a470'
* First throw call stack:
streamURL is an NSString - not a NSURL
try:
NSURL *streamURL = [NSURL URLWithString: [NSString stringWithFormat:#"%#",
allDataDictionarySound[#"stream_url"], nil]];
I'm also not clear where the variable "streamData" is coming from (or what you expect to be in it).
The NSURLConnection is loading the data from the request asynchronously. It looks like you are assuming that the data is loaded synchronously and is available when you're initializing the "player" object. The data will (mostly likely) not be there when player is initialized.