Unable to download private files (e.g.: files which are accessed through login)

53 Views Asked by At

Unable to download private files (e.g.: files which are accessed through login)

I am use inappWebView plugin for my app. When I try to download any file (for example, book from a website which requires login to download books) i get success in the debug console but the downloaded file is some html everytime.

<!DOCTYPE html>
<html  dir="ltr" lang="en" xml:lang="en">
<head>
    <title>NUST - LMS Portal: Log in to the site NUUU</title>
    <link rel="shortcut icon" href="https://lms.nust.edu.pk/portal/pluginfile.php/1/theme_moove/favicon/1682489183/favicon.ico" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="moodle, NUST - LMS Portal: Log in to the site" />
<link rel="stylesheet" type="text/css" href="https://lms.nust.edu.pk/portal/theme/yui_combo.php?rollup/3.17.2/yui-moodlesimple-min.css" /><script id="firstthemesheet" type="text/css">/** Required in order to fix style inclusion problems in IE with YUI **/</script><link rel="stylesheet" type="text/css" href="https://lms.nust.edu.pk/portal/theme/styles.php/moove/1682489183_1682489454/all" />
<script>
//<![CDATA[
var M = {}; M.yui = {};
M.pageloadstarttime = new Date();
M.cfg = {"wwwroot":"https:\/\/lms.nust.edu.pk\/portal","sesskey":"R4zzzTOZro","sessiontimeout":"3600","themerev":"1682489183","slasharguments":1,"theme":"moove","iconsystemmodule":"core\/icon_system_fontawesome","jsrev":"1682489185","admin":"admin","svgicons":true,"usertimezone":"Asia\/Karachi","contextid":1,"langrev":-1,"templaterev":"1682489185"};var yui1ConfigFn = function(me) {if(/-skin|reset|fonts|grids|base/.test(me.name)){me.type='css';me.path=me.path.replace(/\.js/,'.css');me.path=me.path.replace(/\/yui2-skin/,'/assets/skins/sam/yui2-skin')}};
var yui2ConfigFn = function(me) {var parts=me.name.replace(/^moodle-/,'').split('-'),component=parts.shift(),module=parts[0],min='-min';if(/-(skin|core)$/.test(me.name)){parts.pop();me.type='css';min=''}
if(module){var filename=parts.join('-');me.path=component+'/'+module+'/'+filename+min+'.'+me.type}else{me.path=component+'/'+component+'.'+me.type}};
YUI_config = {"debug":false,"base":"https:\/\/lms.nust.edu.pk\/portal\/lib\/yuilib\/3.17.2\/","comboBase":"https:\/\/lms.nust.edu.pk\/portal\/theme\/yui_combo.php?","combine":true,"filter":null,"insertB
I/hwschromium-3355(22220): [INFO:network_service_network_delegate.cc(246)] final url https//*** error_code -3 ip address: ignored
I/flutter (22220): downloadFile: https://lms.nust.edu.pk/portal/pluginfile.php/1541159/mod_resource/content/1/Book_computer%20organization%20and%20design%203rd%20edition.pdf
I/flutter (22220): task id: a4ad0db2-1973-467a-872e-14de9ca6bb53
D/HwCustConnectivityManagerImpl(22220): isBlockNetworkRequestByNonAis, INVALID_SUBSCRIPTION_ID
I/ConnectivityManager(22220): requestNetwork and the calling app is: com.example.nust_unoffical
I/WM-WorkerWrapper(22220): Worker result SUCCESS for Work [ id=a4ad0db2-1973-467a-872e-14de9ca6bb53, tags={ flutter_download_task, vn.hunghd.flutterdownloader.DownloadWorker } ]

Code

 Future<void> downloadFile(String url,
      [String? filename]) async {
    var hasStoragePermission = await Permission.storage.isGranted;
    if (!hasStoragePermission) {
      final status = await Permission.storage.request();
      hasStoragePermission = status.isGranted;
    }
    if (kDebugMode) {
      print('downloadFile: $url');
    }
    if (hasStoragePermission) {
     await FlutterDownloader.enqueue(
          url: url,
          headers: {},
          savedDir: (await getTemporaryDirectory()).path,
          saveInPublicStorage: true,
          fileName: filename);
    }
  }
  • OS: Andriod
  • Version: 14

Device information:

  • Device: pixel 6 pro
  • OS: android
  • plugin version ^1.9.1

Download private files in flutter through web.

0

There are 0 best solutions below