QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms and devices. Check out our detailed guides to make integration easy and fast.

Content

Learn how to store and access files with QuickBlox file storage.

The content module allows storing rich chat attachments, app content, and settings without having to republish them. Using a web interface you or your clients can control and make instant changes to the apps.

Retrieve files

Get a list of files for a current user using the code snippet below.

let page = QBGeneralResponsePage(currentPage: 1, perPage: 20)
QBRequest.blobs(for: page, successBlock: { (response, page, blobs) in
    // process response
}, errorBlock: { (response) in
    // handle errors
    debugPrint("[error: \(response.error?.error)")
})
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:20];

[QBRequest blobsForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *page, NSArray *blobs) {
    // process response
} errorBlock:^(QBResponse *response) {
    // handle errors
    NSLog(@"errors=%@", response.error.error);
}];

Upload file

Upload a file to the cloud using the following code snippet.

// your file - this is an image in our case
guard let imageData = myImage?.pngData() else {
    return
}
QBRequest.tUploadFile(imageData, fileName: "myImage", contentType: "image/png", isPublic: true, successBlock: { (response, uploadedBlob) in
    // File uploaded, do something
    // if blob.isPublic == YES
}, statusBlock: { (request, status)  in
    //Update UI with upload progress
}, errorBlock: { (response) in
    //show upload error
})
// your file - this is an image in our case
NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"arrow.png"]);

[QBRequest TUploadFile:imageData fileName:@"arrow.png" contentType:@"image/png" isPublic:NO successBlock:^(QBResponse *response, QBCBlob *blob) {
    // File uploaded, do something
    // if blob.isPublic == YES
    NSString *url = [blob publicUrl];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
    // handle progress
} errorBlock:^(QBResponse *response) {
    NSLog(@"error: %@", response.error.error);
}];

Download file by UID

If the file is public then it's possible to download it without a session token.

let uid = "d816966db53640e68b304a3cd4e5c0c100"

QBRequest.downloadFile(withUID: uid, successBlock: { (response, fileData)  in
    // do something with fileData
}, statusBlock: { (request, status) in
    let progress = CGFloat(status.percentOfCompletion)
}, errorBlock: { (response) in
    debugPrint("error \(response.error?.error)")
})
NSString *uid = @"d816966db53640e68b304a3cd4e5c0c100";

[QBRequest downloadFileWithUID:uid successBlock:^(QBResponse *response, NSData *fileData) {
    // do something with fileData
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
    NSLog(@"download progress: %f", status.percentOfCompletion);
} errorBlock:^(QBResponse *response) {
    NSLog(@"Response error: %@", response.error.error);
}];

Get file URL

There are two types of file URLs that can be obtained: private and public.

  • Public URL allows anyone to access the file, no authorization token is needed.
  • Private URL can be accessed only by QuickBlox user with a session token.

Get public URL

To receive a public URL, use the code snippet below.

let file: QBCBlob = ...
let publicUrl = file.publicUrl()

// or if you have only file UID
let fileUID = "6221dd49a1bb46cfb61efe62c4526bd800"
let publicUrl = QBCBlob.publicUrl(forFileUID: fileUID)
QBCBlob *file = ...;
NSString *publicUrl = [file publicUrl];
 
// or if you have only file UID
NSString *fileUID = @"6221dd49a1bb46cfb61efe62c4526bd800";
NSString *publicUrl = [QBCBlob publicUrlForFileUID:fileUID];

Get private URL

To get a private URL of the uploaded file, use the following code snippet.

let file: QBCBlob = ...
let privateUrl = file.privateUrl()

// or if you have only file UID
let fileUID = "6221dd49a1bb46cfb61efe62c4526bd800"
let privateUrl = QBCBlob.privateUrl(forFileUID: fileUID)
QBCBlob *file = ...;
NSString *privateUrl = [file privateUrl];
 
// or if you have only file UID
NSString *fileUID = @"6221dd49a1bb46cfb61efe62c4526bd800";
NSString *privateUrl = [QBCBlob privateUrlForFileUID:fileUID];

Updated 24 days ago



Content


Learn how to store and access files with QuickBlox file storage.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.