У меня возникли трудности с загрузкой PDF-файла из mariadb.
Я могу загрузить файл json без каких-либо проблем.
Это то, что я вижу в базе данных Mariadb. Я храню данные вложений в длинном объекте.
Я думаю, что храню массив байтов, но не знаю, почему перед данными стоят (16) и (11702).
по какой-то причине мое приложение не любит загружать длинные объекты, поэтому мне пришлось изменить метод на моем сервере, чтобы получить данные из базы данных.
это метод, который извлекает данные из базы данных::
public static Map get_records(String query_string) {
List results = new ArrayList();
try (Connection connection = data_source.getConnection();
PreparedStatement statement = connection.prepareStatement(query_string)) {
ResultSet resultSet = statement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
int columnCount = metaData.getColumnCount();
while (resultSet.next()) {
Map record = new HashMap();
for (int i = 1; i element['sys_attachment_id'] == attachment_id).toList();
Map attachment = globalProviderContainer.read(form_page_provider.notifier).state.sys_attachment.firstWhere((element) => element['sys_id'] == attachment_id);
attachment_datas.sort((a, b) => a['sys_order'].compareTo(b['sys_order']));
if (attachment_datas.isEmpty) {
}
print("Attachment type: ${attachment['sys_type']}");
print("Attachment name: ${attachment['sys_name']}");
String joined_data = attachment_datas.map((data) => data['sys_data']).join();
print("joined_data (Base64 encoded): ${joined_data}");
// Decode the base64 encoded data
List bytes = base64Decode(joined_data);
String rawString = String.fromCharCodes(bytes);
print("Decoded bytes: ${bytes}");
try {
if (attachment['sys_type'] == 'json') {
// Convert bytes to string
print("Raw string: $rawString");
// Extract the actual byte values
RegExp regex = RegExp(r'\[([^\]]+)\]');
Match? match = regex.firstMatch(rawString);
if (match != null) {
String byteString = match.group(1)!;
List actualBytes = byteString.split(', ').map(int.parse).toList();
// Convert actual bytes to string
String jsonString = String.fromCharCodes(actualBytes);
print("JSON string: $jsonString");
// Parse the JSON string
dynamic jsonData = json.decode(jsonString);
// print("Parsed JSON data: $jsonData");
final blob = html.Blob([jsonData], 'application/json');
// Set the correct file name using sys_name from the attachment
String fileName = '${attachment['sys_name']}';
print("file_name: ${fileName}");
// Create a download link
final url = html.Url.createObjectUrlFromBlob(blob);
final anchor = html.AnchorElement(href: url)
..setAttribute('download', fileName)
..click(); // Trigger the download
// Clean up the URL after the download
html.Url.revokeObjectUrl(url);
} else {
print("Failed to extract byte values from the string");
}
} else if (attachment['sys_type'] == 'pdf') {
// Convert the bytes to a Blob
final blob = html.Blob([bytes], 'application/pdf');
// Set the correct file name using sys_name from the attachment
String fileName = '${attachment['sys_name']}';
print("file_name: ${fileName}");
// Create a download link
final url = html.Url.createObjectUrlFromBlob(blob);
final anchor = html.AnchorElement(href: url)
..setAttribute('download', fileName)
..click(); // Trigger the download
// Clean up the URL after the download
html.Url.revokeObjectUrl(url);
} else {
print("Unhandled file type: ${attachment['sys_type']}");
}
} catch (e) {
print("Error during file processing: $e");
}
}
У меня возникли трудности с загрузкой PDF-файла из mariadb. Я могу загрузить файл json без каких-либо проблем. Это то, что я вижу в базе данных Mariadb. Я храню данные вложений в длинном объекте. [code]SELECT sys_data FROM sys_attachment_data; +---------------------------------------------------------------------------------------------------+ | sys_data | +---------------------------------------------------------------------------------------------------+ | (16)[123, 34, 110, 97, 109, 101, 34, 58, 34, 74, 85, 65, 78, 34, 125, 10] | | (11702)[37, 80, 68, 70, 45, 49, 46, 52, 10, 37, 211, 235, 233, 225, 10, 49, 32, 48, 32, 111, ...] | +---------------------------------------------------------------------------------------------------+
[/code] Я думаю, что храню массив байтов, но не знаю, почему перед данными стоят (16) и (11702). по какой-то причине мое приложение не любит загружать длинные объекты, поэтому мне пришлось изменить метод на моем сервере, чтобы получить данные из базы данных. это метод, который извлекает данные из базы данных:: [code] public static Map get_records(String query_string) { List results = new ArrayList();
final blob = html.Blob([jsonData], 'application/json');
// Set the correct file name using sys_name from the attachment String fileName = '${attachment['sys_name']}'; print("file_name: ${fileName}");
// Create a download link final url = html.Url.createObjectUrlFromBlob(blob); final anchor = html.AnchorElement(href: url) ..setAttribute('download', fileName) ..click(); // Trigger the download
// Clean up the URL after the download html.Url.revokeObjectUrl(url); } else { print("Failed to extract byte values from the string"); } } else if (attachment['sys_type'] == 'pdf') { // Convert the bytes to a Blob final blob = html.Blob([bytes], 'application/pdf');
// Set the correct file name using sys_name from the attachment String fileName = '${attachment['sys_name']}'; print("file_name: ${fileName}");
// Create a download link final url = html.Url.createObjectUrlFromBlob(blob); final anchor = html.AnchorElement(href: url) ..setAttribute('download', fileName) ..click(); // Trigger the download
// Clean up the URL after the download html.Url.revokeObjectUrl(url); } else { print("Unhandled file type: ${attachment['sys_type']}"); } } catch (e) { print("Error during file processing: $e"); } }