Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created April 16, 2015 16:56
Show Gist options
  • Save hayduke19us/0f934c543cfd65cf5894 to your computer and use it in GitHub Desktop.
Save hayduke19us/0f934c543cfd65cf5894 to your computer and use it in GitHub Desktop.
+ (void)uploadImages {
// create an array of image names that need to be uploaded
FMDatabase *db = [FMDatabase databaseWithPath:[[Sync shared] databasePath]];
[db open];
NSUInteger count = 0;
NSUInteger total = [db intForQuery:@"SELECT COUNT(*) FROM images WHERE uploads>0"];
//NSLog(@"%ld records", total);
FMResultSet *results = [db executeQuery:@"SELECT * FROM images WHERE uploads>0"];
while ([results next]) {
count++;
NSString *str = [NSString stringWithFormat:@"Upload Image %ld of %ld", count, total];
[[NSNotificationCenter defaultCenter] postNotificationName:SyncInProgressNotification object:str];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.body = [NSURL fileURLWithPath:[UIImage pathForImage:results[@"name"]]];
uploadRequest.key = [NSString stringWithFormat:@"uploads/normal/%@", results[@"name"]];
uploadRequest.bucket = S3_BUCKET_NAME;
NSNumber *fileSizeValue = nil;
NSError *fileSizeError = nil;
[uploadRequest.body getResourceValue:&fileSizeValue
forKey:NSURLFileSizeKey
error:&fileSizeError];
if (fileSizeValue) {
NSLog(@"value for %@ is %@", uploadRequest.body, fileSizeValue);
uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSizeValue];
}
else {
NSLog(@"error getting size for url %@ error was %@", uploadRequest.body, fileSizeError);
}
[ReportDataController uploadToAWS:uploadRequest name:results[@"name"] deleteFile:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment