Files API for PubNub Unity SDK

Allows users to upload and share files. You can upload any file of up to 5 MB in size. This feature is commonly used in social apps to share images, or in medical apps to share medical records for patients.

When a file is uploaded on a channel, it's stored and managed using a storage service, and associated with your key. Subscribers to that channel receive a file event which contains a file ID, filename, and optional description.

Send file

Description

Upload file / data to specified channel.

Method(s)

pubnub.SendFile().Channel(string).Message(string).CipherKey(string).Name(string).FilePath(string).TTL(int).ShouldStore(bool).Meta(Dictionary<string, string>).Async()
ParameterTypeRequiredDescription
ChannelstringYesChannel to upload the file.
MessagestringOptionalMessage which should be sent along with file to specified channel
FilePathstringYesFull path of the file with file name.
CipherKeystringOptionalKey to be used to encrypt uploaded data. If not provided, PNConfiguration CipherKey is used, if it exists.
TTLintOptionalHow long message should be stored in channel's storage.
ShouldStoreboolOptionalWhether PubNub published file message should be stored in channel history. Defauts to true
MetaDictionary<string, object>OptionalDictionary<string, object> with values which should be used by PubNub service to filter file messages.

Basic Usage

pubnub.SendFile().
Channel("my_channel").
Message("Look at this photo!").
Name("cat_picture.jpg").
FilePath("cat_picture.jpg").
Async((result, status) => {
Debug.Log(result);
if(!status.Error){
Debug.Log("result.Data.ID:" + result.Data.ID);
Debug.Log("result.Timetoken:" + result.Timetoken);
}
});

Returns

The SendFile() operation returns a PNSendFileResult which contains the following properties:

Property NameTypeDescription
DataPNFileDataSee details below.
TimetokenlongReturns a long representation of the timetoken when the message was published.

PNFileData contains the following properties:

Property NameTypeDescription
IDstringReturns the ID of the file.

List channel files

Description

Retrieve list of files uploaded to Channel.

Method(s)

pubnub.ListFiles().Channel(string).Limit(int).Next(string).Async()
ParameterTypeRequiredDefaultDescription
ChannelstringYesChannel to get list of files.
LimitintOptional100Number of files to return.
NextstringOptionalPreviously-returned cursor bookmark for fetching the next page.

Basic Usage

pubnub.ListFiles().Channel("my_channel").Async((result, status) => {
foreach(PNFileInfo pnFileInfo in result.Data){
Debug.Log(pnFileInfo.Name);
Debug.Log(pnFileInfo.ID);
Debug.Log(pnFileInfo.Size);
Debug.Log(pnFileInfo.Created);
}
});

Returns

The ListFiles() operation returns a PNResult``<PNListFilesResult> which contains the following properties:

Property NameTypeDescription
DataPNFileInfoSee details below.
CountintNumber of files returned.
NextstringCursor bookmark for fetching the next page.

PNFileInfo contains the following properties:

Property NameTypeDescription
NamestringName of the file.
IdstringIf of the file.
SizeintSize of the file.
CreatedstringDate the file was created.

Get File Url

Description

Generate URL which can be used to download file from target Channel.

Method(s)

pubnub.GetFileURL().Channel(string).ID(string).Name(string).Async()
ParameterTypeRequiredDescription
ChannelstringYesName of channel within which file with name has been uploaded.
IDstringYesUnique file identifier which has been assigned during file upload.
NamestringYesName under which uploaded file is stored for channel.

Basic Usage

pubnub.GetFileURL().
Channel("my_channel").
ID("fileID").
Name("cat_picture.jpg").
Async((result, status) => {
Debug.Log(status.Error);
Debug.Log(result.URL);
Debug.Log(resultTimeToken);
});

Returns

The GetFileUrl() operation returns a PNFileUrlResult which contains the following properties:

Property NameTypeDescription
URLstringURL which can be used to download remote file with specified name and identifier.

Download file

Description

Download file from specified Channel.

Method(s)

pubnub.DownloadFile().Channel(string).CipherKey(string).ID(string).Name(string).SavePath(string).Async()
ParameterTypeRequiredDescription
ChannelstringYesName of channel within which file with name has been uploaded.
IDstringYesUnique file identifier which has been assigned during file upload.
NamestringYesName under which uploaded file is stored for channel.
SavePathstringOptionalPath to save the file at.
CipherKeystringOptionalKey which should be used to decrypt downloaded data. If CipherKey is not provided, SDK uses CipherKey of PNConfiguration.

Basic Usage

pubnub.DownloadFile().
Channel("my_channel").
ID("fileID").
Name("cat_picture.jpg").
SavePath("cat_picture.jpg").
Async((result, status) => {
Debug.Log(status.Error);
});

The DownloadFile() operation returns a type PNDownloadFileResult which is empty.

Delete file

Description

Delete file from specified Channel.

Method(s)

pubnub.DeleteFile().Channel(string).ID(string).Name(string).Async()
ParameterTypeRequiredDescription
ChannelstringYesName of channel within which file with name needs to be deleted.
IDstringYesUnique file identifier of the file to be deleted.
NamestringYesName of the file to be deleted from the channel.

Basic Usage

pubnub.DeleteFile().
Channel("my_channel").
ID("fileID").
Name("cat_picture.jpg").
Async((result, status) => {
Debug.Log(status.Error);
});

The DeleteFile() operation returns a type PNDeleteFileResult which is empty.

Publish file message

Description

Publish file message from specified Channel.

Method(s)

pubnub.PublishFileMessage().Channel(string).FileId(string).FileName(string).MessageText(string)
ParameterTypeRequiredDefaultDescription
ChannelstringYesName of channel to publish file message
FileIdstringYesUnique file identifier of the file.
FileNamestringYesName of the file.
MessageTextstringOptionalThe payload of type PnPublishMessage.

Basic Usage

pubnub.PublishFileMessage().
Channel("my_channel").
FileID("fileID").
FileName("cat_picture.jpg").
MessageText("Look at this photo!").
Async((presult, pstatus) => {
Debug.Log(presult.Timetoken);
});

Returns

The PublishFileMessage() operation returns a PNPublishFileMessageResult which contains the following properties:

Property NameTypeDescription
TimetokenlongReturns a long representation of the timetoken when the message was published.
Last updated on