Download File using Ionic

I have run into an issue while attempting to download a song/file from a local server using the FileTransfer cordova plugin. While some links are successful in downloading the song, when I test it on my phone, I cannot locate the downloaded file.

Any assistance would be greatly appreciated.

let destination = cordova.file.dataDirectory  + this.currentSong.title+".mp3";
//cordova.file.externalRootDirectory;
fileTrnsfr.download(uri,destination,true).then(
  (entry)=> {
    console.log("Downloaded");

    const alertSuccess = this.alertCtrl.create({

            title: "Download Succeeded",
            subTitle : "File saved in " + destination,
            buttons:['Ok']
    });

    alertSuccess.present();
  },
(error) => {

    console.log("An error occurred: " + error);

    const alertFailure = this.alertCtrl.create({

      title: "Download Failed",
      subTitle : "File downloading failed: "+ destination + " from " + uri,
      buttons:['Ok']
    });

    alertFailure.present();
}

);

}); }

Answer №1

If you encounter the same issue on an Android device, it may be due to a lack of write permission.
You can resolve this by including the following line of code.

  1. Access the manifest.xml file
  2. The path is
    appdir/platforms/android/AndroidManifest.xml
  3. Insert the following line:

    < uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

  4. Verify in the download folder.

  5. After rebuilding or rerunning, you should no longer encounter the issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular - Using HttpClient for handling POST requests

The example provided in the official Angular HttpClient documentation demonstrates how to make a POST request to a backend server. /** POST: add a new hero to the database */ addHero (hero: Hero): Observable<Hero> { return this.http.post<Hero&g ...

What are the techniques for narrowing down this specific type in TypeScript?

Is there a way to modify the following code snippet to eliminate the need for as casting in order to pass the type check successfully? type SupportedHandlerType = string | number | Date type Handler<T> = (data: T[]) => void function example<T ...

What is the best way to run code on every frame within Ionic React?

As a complete beginner in Ionic, React, JSX, and JavaScript in general, I am eager to dive into the world of creating a "mini experimental idle game" for learning purposes. My goal is to update a field every frame and perform some calculations, even thoug ...

Error: JSON parse error - unexpected character 'a' at index 1

I'm encountering an issue while attempting to change the album title from "cars" to "car". The error message I keep receiving is: SyntaxError: Unexpected token a in JSON at position 1. Any ideas on what might be causing this problem? Below is the cu ...

Analyzing the object for interface compatibility

When I receive a query string in one of my REST endpoints using koa-router, each value of the query string object parameter is always a string: { count: "120", result: "true", text: "ok" } Within my codebase, I have an Interface that represents the ...

Retrieve an instance of the property class within a property decorator

I'm attempting to create a decorator called @Prop that will assist me in adjusting attributes for custom elements. This is the desired code: class MyCustomClass extends HtmlElement { get content() { return this.getAttribute('content&apo ...

Is there a possibility of Typescript expressions `A` existing where the concept of truthiness is not the same as when applying `!!A`?

When working with JavaScript, it is important to note that almost all expressions have a "truthiness" value. This means that if you use an expression in a statement that expects a boolean, it will be evaluated as a boolean equivalent. For example: let a = ...

Is it possible to conceal my Sticky Div in MUI5 once I've scrolled to the bottom of the parent div?

Sample link to see the demonstration: https://stackblitz.com/edit/react-5xt9r5?file=demo.tsx I am looking for a way to conceal a fixed div once I reach the bottom of its parent container while scrolling down. Below is a snippet illustrating how I struct ...

"During the constructor initialization, an Angular/TypeScript global variable that was assigned within an

Utilizing HTTP calls to my Web API to fetch 2 API keys for accessing another API. These API keys are fetched using 2 functions: getApiKey() and getAppId() Upon calling these functions within the constructor, the returned value, stored in a global variab ...

"An issue has been identified where TSLint and VSCode fail to display red underlines in

I am currently working on a single .ts file where I am experimenting with configuring tslint and tsconfig. To test the configuration, I intentionally added extra spaces and removed semicolons. Despite running the command tslint filename.ts and detecting e ...

Adding the unzip feature is not within my capabilities

I am a novice Japanese web developer. Unfortunately, my English skills are not great. I apologize for any inconvenience. I am interested in utilizing this specific module: https://www.npmjs.com/package/unzip To do so, I executed the following commands ...

Performing operations on an array: What method do you favor and why? Is there a more efficient approach?

What is the most effective method for checking if an element exists in an array? Are there alternative ways to perform a boolean check? type ObjType = { name: string } let privileges: ObjType[] = [{ name: "ROLE_USER" }, { name: "ROLE_ ...

Ways to conditionally display a component in Next.js without the issue of caching CSS styles

I'm a newcomer to Next.js and I'm still trying to wrap my head around how the caching works. Let's take a look at this simplified example: An index page that displays either Test1 or Test2 components, based on whether the current minute is ...

"Although the NextJS client-side data is present, it seems to be struggling to

I am facing an issue while trying to display fetched data on a blog page. Although the data is successfully retrieved client-side and I can view it using console.log(), it does not appear on the page and the elements remain empty. I am completely puzzled. ...

Angular 2: Issue with disabled functionality not functioning correctly

In my TypeScript code, I have created a boolean variable called readOnlyMode. When this variable is set to true, all elements should be disabled. To achieve this, I am using [disabled]="readOnlyMode" in the HTML for elements that need to be disabled. Howev ...

Prevent receiving the "deprecated warning for current URL string parser" by enabling the useNewUrlParser option

I recently encountered an issue with my database wrapper class that connects to a MongoDB instance: async connect(connectionString: string): Promise<void> { this.client = await MongoClient.connect(connectionString) this.db = this.cli ...

Angular Error - TS2322: The specified type of 'Object | null' cannot be assigned to 'NgIterable<any> | null | undefined'

I encountered an error in homes.component.html while trying to run my Angular project to showcase a list of homes from a JSON file. https://i.stack.imgur.com/D0vLQ.jpg Json File [ { "image_url": "https://images.unsplash.com/ph ...

Retrieve the :id parameter from the URL as a numerical value in Node.js using Typescript

Is there a way to directly get the :id param from the URL as a number instead of a string in order to easily pass it on to TypeORM for fetching data based on a specific ID? Currently, I am using the following approach where I have to create an additional ...

What is the best way to display HTML in this particular situation?

This is the function I am working on: public static monthDay(month: number): string { let day = new Date().getDay(); let year = new Date().getFullYear(); return day + ", " + year; } I am trying to add <span></span> tags around ...

Utilize the up and down arrow keys to scroll through a description list in React

If you want to navigate through the list of Description Details using the tab and shift tab keys, it can be done easily. The default behavior allows for smooth navigation. <dl> <dt style={{ textAlign: "center" }}>Beast of Bodmin< ...