Hedera
Search…
Get file contents
A query to get the contents of a file. Queries do not change the state of the file or require network consensus. The information is returned from a single node processing the query.
Query Signing Requirements
    The client operator private key is required to sign the query request
Constructor
Description
new FileContentsQuery()
Initializes a FileContentsQuery object
1
new FileContentsQuery()
Copied!

Methods

V2
V1
Method
Type
Description
setFileId(<fileId>)
FileId
The ID of the file to get contents for (x.z.y)
Java
1
//Create the query
2
FileContentsQuery query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Sign with client operator private key and submit the query to a Hedera network
6
ByteString contents = query.execute(client);
7
8
//Change to Utf-8 encoding
9
String contentsToUtf8 = contents.toStringUtf8();
10
11
System.out.println(contentsToUtf8);
12
13
//v2.0.0
Copied!
JavaScript
1
//Create the query
2
const query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Sign with client operator private key and submit the query to a Hedera network
6
const contents = await query.execute(client);
7
8
console.log(contents.toString());
9
10
//v2.0.7
Copied!
Go
1
//Create the query
2
query := hedera.NewFileContentsQuery().
3
SetFileID(newFileId)
4
5
//Sign with client operator private key and submit the query to a Hedera network
6
contents, err := query.Execute(client)
7
8
fmt.Println(string(contents))
9
10
//v2.0.0
Copied!
Method
Type
Description
setFileId(<fileId>)
FileId
The ID of the file to get contents for (x.z.y)
Java
1
//Create the query
2
FileContentsQuery query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Sign with client operator private key and submit the query to a Hedera network
6
byte [] contents = query.execute(client);
7
8
//Change to Utf-8 encoding
9
String contentsToUtf8 = contents.toStringUtf8();
10
11
System.out.println(contentsToUtf8);
12
13
//v1.3.2
Copied!
JavaScript
1
//Create the query
2
const query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Sign with client operator private key and submit the query to a Hedera network
6
const contents = await query.execute(client);
7
8
console.log(contents);
Copied!

Get query values

V2
Method
Type
Description
getFileId()
FileId
The ID of the file to get contents for (x.z.y)
Java
1
//Create the query
2
FileContentsQuery query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Get file ID
6
FileId getFileId = query.getFileId();
7
8
//v2.0.0
Copied!
JavaScript
1
//Create the query
2
const query = new FileContentsQuery()
3
.setFileId(newFileId);
4
5
//Get file ID
6
const getFileId = query.getFileId();
Copied!
Go
1
//Create the query
2
query := hedera.NewFileContentsQuery().
3
SetFileID(newFileId)
4
5
//Get file ID
6
getFileId := query.GetFileID()
7
8
//v2.0.0
Copied!

Last modified 6d ago
Copy link