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.

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.

Before you begin

  1. Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
  2. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  3. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  4. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

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
    
}, errorBlock: { (response) in
    
})
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:20];

[QBRequest blobsForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *page, NSArray *blobs) {
    
} errorBlock:^(QBResponse *response) {
    
}];

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
    
}, statusBlock: { (request, status)  in
    // Update UI with upload progress
}, errorBlock: { (response) in
    
})
// 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) {
   
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
    // Update UI with upload progress
} errorBlock:^(QBResponse *response) {
    
}];

The maximum size of the uploaded file depends on the membership plan.

Basic

Startup

Growth

HIPAA

Enterprise

File size limit

10 Mb

25 Mb

50Mb

50Mb

Contact our sales team

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
    
}, statusBlock: { (request, status) in
    let progress = CGFloat(status.percentOfCompletion)
}, errorBlock: { (response) in
    
})
NSString *uid = @"d816966db53640e68b304a3cd4e5c0c100";

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

Get file info

Get information about a file by ID using the method below. This method allows to load the file description model from the server, not the content of the file itself.

QBRequest.blob(withID: 1441441, successBlock: { (response, blob) in
    // Content type in mime format.
    let blobContentType = blob.contentType
    
    // File name.
    let blobName = blob.name;
    
    // Status of the File.
    let blobStatus = blob.status;
    
    // Date when the file upload has been completed.
    let blobCompletedAt = blob.completedAt;
    
    // The size of file in bytes, readonly
    let blobSize = blob.size;
    
    // File unique identifier.
    let blobUID = blob.uid;
    
    // Last read file time.
    let blobLastReadAccessTs = blob.lastReadAccessTs;
    
    // An instance of BlobObjectAccess.
    let blobObjectAccess = blob.blobObjectAccess;
    
    // Coma separated string with file's tags.
    let blobTags = blob.tags;
    
    // File's visibility.
    let blobIsPublic = blob.isPublic;
    
    // Set as YES if you want to update blob's file.
    let blobIsNew = blob.isNew;
    
}, errorBlock: { (response) in
    
})
[QBRequest blobWithID:1441441 successBlock:^(QBResponse * _Nonnull response, QBCBlob * _Nonnull blob) {
    
    // Content type in mime format.
    NSString *blobContentType = blob.contentType;
    
    // File name.
    NSString *blobName = blob.name;
    
    // Status of the File.
    QBCBlobStatus blobStatus = blob.status;
    
    // Date when the file upload has been completed.
    NSDate *blobCompletedAt = blob.completedAt;
    
    // The size of file in bytes, readonly
    NSUInteger blobSize = blob.size;
    
    // File unique identifier.
    NSString *blobUID = blob.UID;
    
    // Last read file time.
    NSDate *blobLastReadAccessTs = blob.lastReadAccessTs;
    
    // An instance of BlobObjectAccess.
    QBCBlobObjectAccess *blobObjectAccess = blob.blobObjectAccess;
    
    // Coma separated string with file's tags.
    NSString *blobTags = blob.tags;
    
    // File's visibility.
    BOOL blobIsPublic = blob.isPublic;
    
    // Set as YES if you want to update blob's file.
    BOOL blobIsNew = blob.isNew;
    
} errorBlock:^(QBResponse *response) {
    
}];

Argument

Required

Description

fileId

yes

ID of the file/blob.

successBlock

yes

Specifies a response block that is called if the request is succeeded. As a result, the response will contain a blob/file description model.

errorBlock

yes

Specifies a response block that is called in case an error is occured.

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];

Delete file

Delete a file by file ID using the deleteBlob() method.

QBRequest.deleteBlob(withID: 1441441, successBlock: { (response) in
    
}, errorBlock: { (response) in
    
})
[QBRequest deleteBlobWithID:1441441 successBlock:^(QBResponse * _Nonnull response) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
   
}];

Argument

Required

Description

fileId

yes

ID of the file/blob.

successBlock

yes

Specifies a response block that is called if the request is succeeded.

errorBlock

yes

Specifies a response block that is called in case an error is occured.

Updated 7 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.