Skip to content
Back

Get File for View in Storage

  • 0
  • Flutter
  • Storage
Mosh Ontong
11 Apr, 2023, 08:44

I want to get my audio file in my appwrite storage, I am using the getFileView , when we trigger this method it will return a buffer of our audio file. Next is I am using audio_player package in flutter. How can I load my audio file as buffer then?

TL;DR
The user is trying to get a file from Appwrite storage and load it as a buffer using the audio_player package in Flutter. They mention that the ByteSource method is not compatible with Flutter Windows. They are looking for an alternative way to get the file view URL for their audio file. Solution: The user can use the getFileView method from the Appwrite SDK to get the Uint8List data for the file. They can then pass this data to the audio_player package for loading the audio file. If ByteSource is not compatible, they can try using URLsource provided in audio_player. They can also refer to the Appwrite discussions
joeyouss
11 Apr, 2023, 09:25

hi

joeyouss
11 Apr, 2023, 09:30

In web, those methods give you URL. You then use any client to download it as buffer - but since you are using Flutter, let me see how it could be done in it

Mosh Ontong
11 Apr, 2023, 13:35

sorry for late reply, I already fix it this issue thank you

joeyouss
11 Apr, 2023, 14:27

Hey @Mosh Ontong - you can let me know your issue

Mosh Ontong
11 Apr, 2023, 14:28

This is how I get the audo files from my appwrite storage

TypeScript
final id = e['\$id'];

    final storage = Storage(ref.read(appwriteClientProvider));
    final url = await storage.getFileView(bucketId: kAudioBucketId, fileId: id);

    final audioItem = AudioLanguage.fromDocument(e);

    return audioItem.copyWith(
      audioFileBytes: url,

And this is the summary of my AudioLanguage model btw

TypeScript
  const AudioLanguage({
    required this.id,
    required this.name,
    required this.vocabularyId,
    required this.sexVoice,
    this.audioFileBytes,
    this.bitrate,
    this.sampleRate,
    this.duration,
    this.channel,
  });
  final String id;
  final String name;
  final String vocabularyId;

  final Uint8List? audioFileBytes;

  final Sex sexVoice;

  final int? channel;
  final int? sampleRate;

  final double? bitrate;
  final double? duration;
Mosh Ontong
11 Apr, 2023, 14:29

is there another way to get the view as url of my audio, just the image shows to us,

Mosh Ontong
11 Apr, 2023, 14:33

ms @joeyouss

Mosh Ontong
11 Apr, 2023, 14:39

To add more information

Basically, I am using the audio_player package in flutter. Though they have this setSource(ByteSource(value)). But according to their documentation

the ByteSource is only some platforms. I am actually creating a flutter windows, it seems that ByteSource is not compatible in flutter windows. That is why, I want to find another way like I want to get the exact url of my audio file

Mosh Ontong
11 Apr, 2023, 15:06

I am actually using this but this is not safe, though we can set up the permission of the bucket but the problem is that when I accessing that url with a permision that only user can access. It gives me unauthorized access. Thats why I think we have to create another method that can get the url

joeyouss
11 Apr, 2023, 17:20

Thank you for sharing it here @Mosh Ontong . getFileView actually gives the data (file) https://github.com/appwrite/sdk-for-flutter/blob/master/lib/services/storage.dart#L203 - it gives you a Uint8list and whatever library you are using should be able to take that as input - I see you are using ByteSource but it has a limitation so you might want to use URLsource provided in audio_player? but you would need the file URL for which I recommend: https://github.com/appwrite/appwrite/discussions/3474

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more