I use parsing for my chat. When I upload files, I save the URL and send the URL to other users, who can then upload the files through this URL.
Here is my code for downloading files:
+ (void)uploadBlob:(NSData *)blob fileName:(NSString *)fileName type:(NSString *)type {
if ([self private_checkCloudForbidden]) {
return;
}
if (CHOSEN_SERVER_DATABASE == ServersQuickBlox) {
if ([Format isThumbnailWithBlobFileName:fileName]) {
type = @"image";
}
NSString *qbContentType = @"";
if ([type isEqualToString:@"image"]) {
qbContentType = @"image/jpg";
}
[QBContent TUploadFile:blob fileName:fileName contentType:qbContentType isPublic:YES delegate:[CloudDelegate sharedInstance]];
}
else if (CHOSEN_SERVER_DATABASE == ServersParse) {
PFFile *file = [PFFile fileWithName:fileName data:blob];
[file saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error){
NSLog(@"Error: %@", [[error userInfo] objectForKey:@"error"]);
} else {
[CloudHandler didUploadBlobWithFileName:file.name blobID:file.url];
}
}];
}
}
and in the CloudHandler didUploadBlobWithFileName method, I will save the file url as blobID. And this is how I upload files via blobID / url when using QuickBlox:
+ (void)downloadWithBlobId: (NSString *)blobID {
if ([self private_checkCloudForbidden]) {
return;
}
if (CHOSEN_SERVER_DATABASE == ServersQuickBlox) {
[QBContent TDownloadFileWithBlobID:blobID.integerValue delegate:[CloudDelegate sharedInstance]];
}
else if (CHOSEN_SERVER_DATABASE == ServersParse) {
}
}
I did not find an API to download the file at the url. (this is a little strange if parsing makes url or blobID useless
EDIT:
The reason I don't use attributes like 'file':
1. I can't store 'file' on local database. It has to be the blobID or URL.
2. when I send a rich message, I can send along the blobID, so that the receiver does not have to fetch the object first before downloading the binary.
source
share