Issue with AngularJS: 'FileConstructor is not a valid constructor'

Error Alert: The FileConstructor is not functioning as expected, displaying the error message 'FileConstructor is not a constructor (evaluating 'new File([blob], "filename.png")')

Upon researching, I came across a related query Alternative for File() constructor for safari but unfortunately, no satisfactory alternatives were found.

Is there a potential workaround for this issue when working with Ionic Framework on IOS?

Concerning Javascript:

a = Base64 image.

 var blob = new Blob([a], {type: 'image/png'});

        console.log(blob);
        $scope.Issue14 = blob;

       var nfile = new File([blob], "filename.png");

        console.log(nfile);
        $scope.Issue15 = nfile;

       var _file = nfile;

        console.log(_file);
        $scope.Issue16 =  _file;

        $scope.Images.push({"img": _file});  

Answer №1

I am experiencing a similar problem with File and Safari. After conducting some research, I stumbled upon a solution that appears to be effective for me... hopefully, it will prove helpful to you:

Instead of utilizing new File, I add name and lastModifiedDate attributes to the blob.

 blob.name = "filename.png";
 blob.lastModifiedDate = new Date();

It may not be a traditional file, but you can use it in the same manner...

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

Is there a single code that can transform all standard forms into AJAX forms effortlessly?

When manipulating my 'login' form, I love using this code to submit it to the specified url and display the response in the designated id. The method of submission is defined as well. It's a great solution, but is there a way to streamline ...

Adjusting the color of a cell based on its value

Currently, I am in the process of converting a CSV file to an HTML table by utilizing a tool available at . However, I am facing a challenge in modifying the background color of cells based on their values. I would greatly appreciate any help or guidance w ...

Refresh a specific div element utilizing jQuery

I am facing a challenge with my data table in my Spring MVC project. I want to be able to update or remove data from the table without having to reload the entire page. Below is an example of the HTML div element: <div id="datatable"> </div> ...

Is there a way to delete added information using a trigger that has been inserted through ajax?

I created a function in jQuery and Ajax to add information from a separate PHP file to another file. Let's name the destination file "Homepage" and the file with the data "Template". Here is the function I used: var box = $('#infoPageContainer& ...

The Ajax POST call was unsuccessful

I seem to be encountering an issue, even though everything appears to be correct. I am currently developing on localhost and I am facing difficulties loading a file. This is the code I am using. I am working in NetBeans and the console shows no errors. & ...

Tips for Deploying Your NuxtJS Project on a Shared Hosting Service

After creating my NuxtJS project locally, I am now facing the challenge of deploying it to a shared hosting provider like Host Gator. Since I intend to utilize the server side rendering feature of NuxtJS, I know I need to execute the following command: n ...

Ways to send user input to a function within a React component

I am currently working on implementing a simple feature where users can search posts by their tags. To achieve this, I have created the Feed.jsx component with the following code: "use client"; import { useState, useEffect } from "react&quo ...

Having trouble receiving accurate intellisense suggestions for MongoDB operations

Implementing communication between a node application and MongoDB without using Mongoose led to the installation of typing for both Node and MongoDB. This resulted in the creation of a typings folder with a reference to index.d.ts in the server.ts file. In ...

Automatically pre-fill and send hidden form

I'm working on a form and have set up a handler for the submit button like this: $( '#submit_btn' ).click( function( data ){ theForm = document.getElementById( 'realForm' ); theForm.meetingName.value = document.getElement ...

AngularJS combined with jVectorMap allows for the seamless rendering of small interactive

I am facing a similar issue to one discussed here, but with some minor differences. Initially, my map loaded without any problem on the site. However, after adding Angularjs to the site, I noticed a 'small' map issue. It seems like a simple code ...

handling component interaction with react-redux store

Currently, I am in the process of developing my first significant project using react-redux. While trying to establish state mapping between components in react-redux, I seem to have missed a crucial step. Almost everything is functioning smoothly except ...

Guide on configuring Angular validation to trigger on blur events and form submission

Validation in Angular is currently set to update on model change, but this method can be unfriendly for user interface as it displays errors upon keyup. An optimal solution would involve displaying error messages on blur and also on form submission. After ...

Is there a way to assign the value of a textfield to a session attribute in JSP prior to rendering?

Imagine I have the following code snippet: <html> <head> <script> function setSession() { var roll=document.getElementById("rollno").value; session.setAttribute("rollno", roll); } & ...

What is the proper way to install the Start Angular template?

I recently started learning Angular development and came across this template that I would like to use. To set it up, I followed these steps: sudo apt-get install -y nodejs sudo apt-get install -y npm sudo npm install -g bower sudo npm install -g grunt-cl ...

Getting a null value for active user after completing the sign-in process

I am using local storage to store username and password. However, I am encountering an issue where the active user is returning null after a certain line of code, and I am unsure why. console.log("I am the Active user: " + activeUser); const me ...

JavaScript - Retrieve a nested property within an object using an array of strings

I possess an object in the following format { metadata: { correlationId: 'b24e9f21-6977-4553-abc7-416f8ed2da2d',   createdDateTime: '2021-06-15T16:46:24.247Z' } } and I possess an array containing the properties I wish to re ...

Implement an expand/collapse effect using CSS3 transitions

How can I implement a smooth expand/collapse effect? function expandCollapse(shID) { if (document.getElementById(shID)) { if (document.getElementById(shID + '-show').style.display != 'none') { document.getElem ...

JavaScript, detecting repeated characters

I need to create a script that checks an input box (password) for the occurrence of the same character appearing twice. This script should work alongside existing regex validation. I believe I will need to use a loop to check if any character appears twice ...

How to manage rejections in async/await within the Array#map method

In my Node 8.1.2 project, I encountered a scenario where one file is calling another file's function within a map structure. While in a real example, I would normally use Promise.all on the map, that specific implementation is not the focus of this qu ...

Unable to use NodeJS await/async within an object

I'm currently developing a validation module using nodeJs and I'm facing difficulties understanding why the async/await feature is not functioning correctly in my current module. Within this module, I need to have multiple exports for validation ...