// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'dart:convert';
import 'dart:typed_data';
import 'package:firebase_auth/firebase_auth.dart';
import '../../backend/firebase_storage/storage.dart';
Future<String?> uploadRawFileToFB(String bytes) async {
try {
// Get the current user's UID to use in the file path
final String currentUserUid =
FirebaseAuth.instance.currentUser?.uid ?? 'default_user';
// Convert the raw bytes string to a Uint8List
Uint8List fileBytes = Uint8List.fromList(utf8.encode(bytes));
String directoryPath = '/users/' + currentUserUid + '/pdfs';
String fileName = 'file-${DateTime.now().millisecondsSinceEpoch}.pdf';
// Upload the file to Firebase and get the download URL
String? downloadUrl =
await uploadData(directoryPath + '/' + fileName, fileBytes);
return downloadUrl;
} catch (e) {
print('Error uploading file: $e');
return null;
}
}
API Raw body Text response looks like:
%PDF-1.7
%����
1 0 obj
<</Type /Catalog
/Pages 2 0 R
/ViewerPreferences <</DisplayDocTitle true>>
/Outlines 4 0 R
/StructTreeRoot 5 0 R
/MarkInfo <</Marked true>>
/Lang (nl)
/Metadata 6 0 R>>
endobj
7 0 obj
<</Length 9 0 R
/Filter /FlateDecode