nativescript:如何在使用Downloader插件时添加扩展名

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

您好我需要从外部URL下载一个音频文件,它可以工作,但没有.mp3扩展名,这是播放器识别它所必需的,这是我的代码:

getAudio(token:String,interestPointId:string,link:string, audioId):string{

    const downloadManager = new Downloader();
    var path:string;

    const imageDownloaderId = downloadManager.createDownload({
        url:link        

      });

      downloadManager
      .start(imageDownloaderId, (progressData: ProgressEventData) => {
        console.log(`Progress : ${progressData.value}%`);
        console.log(`Current Size : ${progressData.currentSize}%`);
        console.log(`Total Size : ${progressData.totalSize}%`);
        console.log(`Download Speed in bytes : ${progressData.speed}%`);
      })
      .then((completed: DownloadEventData) => {


        path=completed.path;           
        console.log(`Image : ${completed.path}`);
      })
      .catch(error => {
        console.log(error.message);
      });
    return path;    

}

只是示例中的修改版本(https://market.nativescript.org/plugins/nativescript-downloader

目标是下载文件并获取它的路径,而名称应该是~path / idAudio.mp3

欢迎任何帮助,提前谢谢!

download nativescript
1个回答
0
投票

你可以设置fileName和createDownload上的路径没有记录(我忘了)你可以使用interface所以你需要的是以下我也建议你不要尝试将文件保存到项目根目录,例如~/blah/blah.mp3在真正的ios设备上会失败

downloadManager.createDownload({
        url:link        
        path:somePath,
       fileName: 'idAudio.mp3'
      }
© www.soinside.com 2019 - 2024. All rights reserved.