Unable to upload images on Phonegap ios using formdata

I am facing an issue with image upload in my Phonegap application for iOS. The image upload is not working at times and I am unsure of the exact reason behind this. I am using FormData to upload the image as shown below:

<input id="uploadImage" type="file" name="attachment" onchange="angular.element(this).scope().uploadFile(this.files)"/>
<button type="submit" class="ui-btn ui-btn-b" ng-click="post()"> Upload file</button>

In my JS code, I have the following function that handles the file upload:

$scope.uploadFile = function(files)
{
   var fd = new FormData();
   //Take the first selected file
   fd.append("attachment", files[0]);
   $localStorage.fd = fd;
};

$scope.post=function()
 {
    var fd=$localStorage.fd;
    $http.post(httpurl, fd,
       {
         headers: {'Content-Type': undefined },
         transformRequest: angular.identity
        })
    .success(function (res) {
    alert("Image upload successfully");
    })
    .error(function(res){
    alert("Image not uploaded");
})

However, the problem persists as the image upload works inconsistently. I have tried uploading the same image multiple times but faced the same issue each time. Any insights on how to resolve this issue would be greatly appreciated. Thank you.

Answer №1

To sum it up: Safari iOS does not support the append function.

I recently encountered a similar problem that puzzled me for quite some time. It turns out that certain FormData functions do not work in various browsers, including Safari iOS.

For more information on compatibility, you can check out this list here: https://developer.mozilla.org/en-US/docs/Web/API/FormData

To work around this issue, I found that placing my fields within a form and passing the entire form using new FormData(form) resolved the problem.

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

Ways to categorize by a particular date

const vehicleDetails = [ { "record_id": "2ff8212f-5ec9-4453-b1f3-91840a3fb152", "status_date_activity": { "On Rent": 1662021991000 } }, { "record_id": "c8c1 ...

What is the procedure for initiating a POST request when the payload is ready for submission?

After a successful payment, my success page is displayed with a URL that includes a query parameter. I want to make a POST request to my API endpoint when the page loads, but I'm encountering an issue where the first POST request is empty (router.quer ...

utilizing vuex store within a JavaScript document

Currently, I'm encountering an issue while attempting to access my store from a helper function file: import store from '../store' let auth = store.getters.config.urls.auth An error is being logged: Uncaught TypeError: Cannot read prop ...

Having difficulty assigning a selected value in select2 using JavaScript with Ajax mode

I am trying to use a select2 element that loads data from a database using ajax. My goal is to load the value from the database and have it selected as the default value in edit mode. However, I am encountering issues with using the trigger function to ach ...

"Seamlessly Integrating AngularJS with WebGL for Stunning Canvas Inter

I am new to AngularJS and curious about its compatibility with HTML5 Canvas or WebGL. Are there any tutorials available on how to integrate AngularJS into a view that uses these technologies? I have noticed some games claiming to be developed with Angular ...

"Cookie Magic: Unleashing the Power of Ajax and

I am currently working on an ASP.NET 3.5sp1 application with a single page layout where all interactions are handled through ajax, eliminating the need for postbacks. The website in question is . This app does not require user accounts and allows anonymou ...

Implementing dynamic props in Vue2 component by passing arbitrary named variables

Having recently delved into Vue, I am facing a challenge that has left me scratching my head after consulting the documentation: I am struggling to pass an arbitrarily named variable as a prop to a component instance. As per my understanding, props serve ...

Alter the background color of the entire document to (EDIT) in the top dialog box

<script> $(function() { $( "#dialog" ).dialog(); }); </script> </head> <body> <div id="dialog" title="Basic dialog"> <p>This default dialog box can display information. It can be moved, re-sized, and closed ...

What are some ways to stop the default event action from occurring when a parent HTML element has an event handler attached to it?

I have a bunch of hyperlinks on my webpage that I want to ajaxify so that clicking on a link deletes the associated item. I attached an event handler to a parent container like this: <div id="parent"> <a href='#' data-itemid='1& ...

What is the method to extract mimeType from an HTMLImageElement?

After researching the MDN documentation on HTMLImageElement, I found no mention of the mimeType. I did come across some resources explaining how to retrieve the mimeType from a File Object. However, my specific requirement is to extract the mimeType from ...

Display or conceal UIImageView within a UITableView cell

Looking for advice on the optimal method for toggling the visibility of an UIImageView when a UIButton in a UITableViewCell (custom class) is clicked. Currently, the row height is determined using UITableViewAutomaticDimension and all necessary constraint ...

An issue with jQuery's :not selector and hash symbol syntax

I encountered a syntax error that is quite charming. It appears when attempting to select all anchor tags without an href attribute containing a placeholder URL, such as href="#". Here are the attempts I have made: $("a:not(href='#')"); // cha ...

obtainServerSideProps query parameter

Hey there, I'm trying to use NextJS and its getServerSideProps function to send an API Request, but I'm having trouble passing my ID Query Parameter along. The URL for my API is: http://localhost:3001/product/${id} Below is my code: const rout ...

Tutorial on integrating jquery ui's '.droppable' feature with the jQuery '.on' method

I have a main div with three inner divs labeled 1, 2, and 3 as shown below: <div id="main"> <div style="height:30px; background-color:yellow;" class="bnr">Banner</div> <div style="height:30px; background-color:yellow;" class=" ...

Angular 1 Makes Drag and Drop a Breeze

I am exploring a new feature in Angular and trying to create a drag and drop functionality between 2 tables without sorting. Despite no errors in the console, I cannot see any results being displayed. My slight variation in requirements is causing some con ...

Attention all controllers summoned from one AngularJS document

Having recently delved into the world of AngularJS and Ionic, I've exhaustively searched for solutions both on this forum and beyond. Despite my efforts, nothing seems to be working. My goal is to create an application with a homepage featuring a ser ...

Creating an infinite SVG animation loop using JavaScript

elem = document.querySelectorAll("path"); function task(i) { setTimeout(function() { elem[i].animate({fill: 'green'}, { // timing options duration: 150, iterations: 1 }); }, 150*i); } for(var i=0;i<8;i++){ task(i); } < ...

Modifying the value of a property in an object array created using the map method is ineffective

I have a collection of objects: https://i.sstatic.net/XNrcU.png Within the collection, I wished to include an additional property to the objects. To achieve this, I utilized the map function: returnArray = returnArray.map((obj) => { obj.active = "fal ...

Click to load additional data until the list has reached its full length

<ng-container *ngFor="let item of itemList | slice:0:3"> <mat-checkbox>{{item}}</mat-checkbox> </ng-container> <div> <button id="loadMore">Load More</button> </div> I wo ...

Using jQuery to iterate through an array and reverse its order

Is there a way to loop through an array and change the CSS background color chronologically rather than randomly? Additionally, is it possible to reverse through the same array when the back button is clicked? http://jsfiddle.net/qK2Dk/ $('#right&a ...