如何使用 GridFS 从 mongodb 下载音频文件

问题描述 投票:0回答:0

我对 Rust 还很陌生,正在尝试从 mongodb 集合中下载音频文件。我已经通过这个功能上传了

pub async fn save_voice_note(collection: Collection<Users>, DB: Database , userid: ObjectId, filepath: String) -> ObjectId{
    
    let mut bucket = GridFSBucket::new(DB.clone(), Some(GridFSBucketOptions::default()));
    let id = bucket
    .upload_from_stream("hello.wav", "hello.wav".as_bytes(), None)
    .await;

    
    // Create a filter to match the user with the given ID
    let filter = doc! { "_id": userid };

    // Create an update document to append the voice note ID to the `voice_notes` array
    let update = doc! { "$push": { "voice_notes": id.clone().expect("ID should be a string").to_hex()} };

    // Create an UpdateOptions instance with default options
    let options = UpdateOptions::builder().build();

    // Call the update_one method on the collection with the filter, update, and options
    let result = collection.update_one(filter, update, options).await;

    println!("Audio file saved in MongoDB using GridFS!");
    id.expect("ID should be a string")
}

现在我想下载它并播放它。这是我到目前为止所写的,但它给了我错误。

pub async fn play_audio(DB: Database , id: ObjectId) {
    
    let bucket = GridFSBucket::new(DB, None);
    let mut output = File::create("downloaded_file.wav").await;
    let futures_writer = tokio_writer.compat_write();
    bucket.download_to_futures_0_3_writer(id, futures_writer).await;

    Ok(());
}

错误是error[E0599]: no method named `download_to_futures_0_3_writer` found for struct `GridFSBucket` in the current scope

完全错误

error[E0599]: no method named `download_to_futures_0_3_writer` found for struct `GridFSBucket` in the current scope
   --> src/db_config.rs:168:12
    |
168 |     bucket.download_to_futures_0_3_writer(id, futures_writer).await;
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `GridFSBucket`
mongodb rust audio gridfs
© www.soinside.com 2019 - 2024. All rights reserved.