Mike
Mike

Reputation: 1

Where can I securely store audio in flutter so that I can use it again later?

I want to store audio recordings in my Flutter App, I have created a POC that can do it, I'm wondering how to get a director that I can securly store them, Right now I'm just using a temp directory in this code, I would like to replace that with a folder that is secured (however Android or iOS would do that, I'm not trying to invent secure storage.)

import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';

class _AudioRecorderState extends State<AudioRecorder> {
  // Define a variable to hold the file path for the audio recording
  late String filePath;
  ...
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      ...
      body: Center(
        child: ElevatedButton(
          child: Text('Start Recording'),
          onPressed: () async {
            audioPlayer.start();
            await microphoneRecorder.start();
            filePath = await _getFilePath(); // Get the file path
          },
        ),
      ),
    );
  }

  // Function to get the temporary directory and create a file path for the audio recording
  Future<String> _getFilePath() async {
    final directory = await getTemporaryDirectory();
    return '${directory.path}/recording.wav';
  }

  // Function to save the audio recording to a file
  Future<void> _saveRecording() async {
    final recording = await microphoneRecorder.stop();
    final file = File(filePath);
    await file.writeAsBytes(recording!.buffer.asUint8List());
  }

  @override
  void dispose() {
    audioPlayer.dispose();
    _saveRecording();
    super.dispose();
  }
}

I hope there is a user directory that is secure that I can use, and not having to resort to encrypting it myself with like, encrypt.dart functions.

I tried looking at the docs, and I have not found a way to securly store the recordings, I have found encryption code, but I would prefer to offload it to the OS.

Upvotes: 0

Views: 125

Answers (0)

Related Questions