ZouhirBensm commented on issue #364: URL: https://github.com/apache/cordova-plugin-file/issues/364#issuecomment-2816781130
Hi All! I read this thread, and some advanced concepts are being discussed here I see! (Sorry for being a lay man developer, please go easy on me) I am using this implementation, and I can download up to ~30 MB of data on my A53 Samsung Android device with it: ``` // File download function downloadResult(taskId) { cordova.plugin.http.sendRequest( `http://192.168.2.18:3007/poc4/download/${taskId}`, // `https://aiffamp3.com/poc4/download/${taskId}`, // Production URL { method: 'get', responseType: 'arraybuffer', headers: { 'Accept': 'audio/mpeg' } }, function (response) { console.log('Download successful, saving file'); const blob = new Blob([response.data], { type: 'audio/mpeg' }); saveMP3( blob, function (savedPath) { statusDiv.innerHTML = `Download complete! File saved to:<br>${savedPath}`; convertBtn.disabled = false; }, function (error) { console.error('Save file failed:', error); statusDiv.textContent = `Failed to save file: ${error.message || 'Unknown error'}`; convertBtn.disabled = false; } ); }, function (error) { console.error('Download failed:', error); statusDiv.textContent = `Download failed: ${error.error || error.message || 'Unknown error'}`; convertBtn.disabled = false; } ); } // Save MP3 file to device function saveMP3(blob, successCallback, errorCallback) { window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function (rootDir) { rootDir.getDirectory('Download', { create: true }, function (downloadDir) { const fileName = `converted_${Date.now()}.mp3`; downloadDir.getFile(fileName, { create: true }, function (fileEntry) { fileEntry.createWriter(function (writer) { writer.onwriteend = function () { successCallback(fileEntry.toURL()); }; writer.onerror = function (error) { errorCallback(new Error('Failed to write file')); }; writer.write(blob); }, function (error) { errorCallback(new Error('Failed to create file writer')); }); }, function (error) { errorCallback(new Error('Failed to create file')); }); }, function (error) { errorCallback(new Error('Failed to access Download directory')); }); }, function (error) { errorCallback(new Error('Failed to access external storage')); }); } } ``` The app crashes when trying to download ~60 MB of data. I was looking for a bullet proof solution capable to download files .mp3 up to ~ +300 MB. I'm using this for the request: cordova-plugin-advanced-http I'm using this for the download: cordova-plugin-file (uses cordova.file). All help or recommendations would be appreciated. Extra information: ``` Cordova Packages: cli: 12.0.0 common: 5.0.1 create: 5.0.0 lib: 12.0.2 common: 5.0.1 fetch: 4.0.0 serve: 4.0.1 Project Installed Platforms: android: 14.0.0 Project Installed Plugins: cordova-plugin-advanced-http: 3.3.1 cordova-plugin-file: 8.1.3 cordova-plugin-file-transfer: 2.0.0 Environment: OS: Ventura 13.1 (22C65) (darwin 22.2.0) x64 Node: v18.19.0 npm: 10.2.3 android Environment: android: [=======================================] 100% Fetch remote repository... Available Android targets: ---------- id: 1 or "android-35" Name: Android API 35, extension level 13 Type: Platform API level: 35 Revision: 2 ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org For additional commands, e-mail: issues-h...@cordova.apache.org