- The client operator private key is required to sign the query request
- Please see the transaction and query fees table for the base transaction fee
- Please use the Hedera fee estimator to estimate your query fee cost
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Retrieve the contents of a Hedera File Service (HFS) file with FileContentsQuery, returning the raw file bytes stored on the consensus network.
| Constructor | Description |
|---|---|
new FileContentsQuery() | Initializes a FileContentsQuery object |
new FileContentsQuery()
| Method | Type | Description |
|---|---|---|
setFileId(<fileId>) | FileId | The ID of the file to get contents for (x.z.y) |
//Create the query
FileContentsQuery query = new FileContentsQuery()
.setFileId(newFileId);
//Sign with client operator private key and submit the query to a Hedera network
ByteString contents = query.execute(client);
//Change to Utf-8 encoding
String contentsToUtf8 = contents.toStringUtf8();
System.out.println(contentsToUtf8);
//v2.0.0
//Create the query
const query = new FileContentsQuery()
.setFileId(newFileId);
//Sign with client operator private key and submit the query to a Hedera network
const contents = await query.execute(client);
console.log(contents.toString());
//v2.0.7
//Create the query
query := hedera.NewFileContentsQuery().
SetFileID(newFileId)
//Sign with client operator private key and submit the query to a Hedera network
contents, err := query.Execute(client)
fmt.Println(string(contents))
//v2.0.0
// Create the query
let query = FileContentsQuery::new()
.file_id(file_id);
// Submit the query to a Hedera network
let contents = query.execute(&client).await?;
// Print the contents to the console
println!("File contents: {:?}", String::from_utf8_lossy(&contents));
// v0.34.0
| Method | Type | Description |
|---|---|---|
getFileId() | FileId | The ID of the file to get contents for (x.z.y) |
//Create the query
FileContentsQuery query = new FileContentsQuery()
.setFileId(newFileId);
//Get file ID
FileId getFileId = query.getFileId();
//v2.0.0
//Create the query
const query = new FileContentsQuery()
.setFileId(newFileId);
//Get file ID
const getFileId = query.getFileId();
//Create the query
query := hedera.NewFileContentsQuery().
SetFileID(newFileId)
//Get file ID
getFileId := query.GetFileID()
//v2.0.0
// Create the query
let query = FileContentsQuery::new()
.file_id(file_id);
// Get the file ID
let file_id = query.get_file_id();
// v0.34.0
Was this page helpful?