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.
Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
Before you begin
- 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.
- Configure QuickBlox SDK for your app. Check out our Setup page for more details.
- Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.
Upload file
Upload a file to the cloud using the following code snippet.
String url = "content://images/test.jpg";
bool public = false;
try {
QBFile? file = await QB.content.upload(url, public: public);
} on PlatformException catch (e) {
// Some error occurred, look at the exception message for more details
}
Argument | Required | Description |
---|---|---|
url | yes | URL of a file. |
public | no | Boolean parameter. Specifies file visibility. If the file is public then it's possible to download it without a session token. Default: false. |
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 |
Get file info
Get information about a file by ID using the getInfo()
method below. This method allows to load the file description model from the server, not the content of the file itself.
int fileId = 98239423;
try {
QBFile? file = await QB.content.getInfo(fileId);
if (file != null) {
int id = file!.id;
String uid = file!.uid;
}
} on PlatformException catch (e) {
// Some error occurred, look at the exception message for more details
}
Argument | Required | Description |
---|---|---|
fileId | yes | ID of the file. |
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.
String fileUid = "sdfldsj890dfLKJJerJdkn8";
try {
String! url = await QB.content.getPublicURL(fileUid);
} on PlatformException catch (e) {
// Some error occurred, look at the exception message for more details
}
Argument | Required | Description |
---|---|---|
fileUid | yes | File unique identifier. You can get the fileUid from the file recieved as a result of the getInfo() method. |
Get private URL
To get a private URL of the uploaded file, use the following code snippet.
String fileUid = "sdfldsj890dfLKJJerJdkn8";
try {
String! url = await QB.content.getPrivateURL(fileUid);
} on PlatformException catch (e) {
// Some error occurred, look at the exception message for more details
}
Argument | Required | Description |
---|---|---|
fileUid | yes | File unique identifier. You can get the fileUid from the file recieved as a result of the getInfo() method. |
Updated over 2 years ago