Issues with the File plugin in Ionic 2

Currently, I am working on integrating Quickblox into my Ionic2 application. I have successfully implemented all the required functionalities except for file uploading. In Quickblox, there is a specific function that needs to be used for uploading files, as per their JavaScript documentation:

var inputFile = $("input[type=file]")[0].files[0];

var params = {name: inputFile.name, 
     file: inputFile, 
     type: inputFile.type, 
     size: inputFile.size, 
     public: false};

QB.content.createAndUpload(params, function(err, response){
  if (err) {
    console.log(err);
  } else {
    console.log(response);
    var uploadedFile = response;
    var uploadedFileId = response.id;
  }
});

So, I translated the above code to TypeScript and it looks like this:

uploadFile(filename) {
    File.resolveDirectoryUrl(cordova.file.dataDirectory).then(
        (dirEntry) => {
            File.getFile(dirEntry, filename, { create: false }).then(
                (fileEntry) => {
                    console.log(fileEntry);
                    fileEntry.file((file) => {
                        console.log(file);
                        var params = {
                            name: file['name'],
                            file: file,
                            type: file['type'],
                            size: file['size'],
                            'public': false
                        };
                        quickblox.content.createAndUpload(params,
                            (err, response) => {
                                if (err) {
                                    console.log(err);
                                } else {
                                    console.log(response);
                                    var uploadedFileId = response.id;
                                    var msg = {
                                        type: 'groupchat',
                                        body: "[attachment]",
                                        extension: {
                                            save_to_history: 1,
                                        }
                                    };
                                    msg["extension"]["attachments"] = [{ id: uploadedFileId, type: 'photo' }];
                                    quickblox.chat.send(this.xmpp_room_jid, msg);
                                }
                            });
                    })
                }).catch(
                (err) => {
                    console.log(err);
                }
                );
        }
    );
}

Although I receive successful responses from the Quickblox server, I noticed that the uploaded image appears to have 0 bytes when viewed in the Quickblox admin console. After examining the code and comparing with the Quickblox example app, the only noticeable difference was in the File object.

This is the File object retrieved in my Ionic 2 app:

https://i.sstatic.net/TmEfT.png

And this is the File object from the Quickblox JavaScript example:

https://i.sstatic.net/APQjp.png

All other aspects appear identical except for this disparity in the File object. I suspect this may be causing the issue, but being new to this field, I haven't been able to figure out how to cast the File object in Ionic to match the one in the JavaScript example. I appreciate any assistance or insights provided. Thank you.

EDIT:

Here are the request/response logs from my Ionic app:

https://i.sstatic.net/CilL7.png

https://i.sstatic.net/5IkuS.png

https://i.sstatic.net/01W7H.png

https://i.sstatic.net/1VsIN.png

https://i.sstatic.net/KF4h9.png

https://i.sstatic.net/oKWgy.png

Answer №1

I'm having trouble with connecting to the chat feature using QuickBlox. The documentation is not very helpful in guiding me through the process of creating a session and opening a video call. Can someone provide me with the code needed for this task?

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

Showing list data from script to template in vue - A step-by-step guide

My task involves displaying data from the main table in MySQL. I need to show the type of each major by comparing it with the id in the faculty table. I have successfully logged this information using console.log, but I'm unsure how to display it on t ...

Determine if the browser displays <select multiple> as a modal dialog

Is it possible to use JavaScript to detect whether a specific browser displays a focused <select multiple> element as a popup or strictly as an inline box? On certain platforms, like the Android Browser and iOS Safari, the appearance of a popup can ...

How can I resolve the infinite loop issue caused by Angular Auth guard when using routing?

My current struggle lies within the authentication guard logic and routing setup. In my app-routing.module.ts file, I have defined 3 routes: const routes: Routes = [ { path: '', loadChildren: () => import('./browse/browse.mod ...

What are the steps to globalize the ng-bootstrap datepicker?

For my current project, I am utilizing the ng-bootstrap datePicker component. The demo for my simple datePicker widget can be found here. However, I am now seeking to internationalize it by setting it to use the Russian language. Any assistance with this ...

Utilizing the Google Translate API within an ASP MVC framework to translate a div's content from English to Arabic

Currently, I am working on a small project that involves two divs: one for English and another for Arabic. Despite creating the project, I am encountering an issue with getting the translation from English to Arabic. Below is the code I have attempted, but ...

Flipped the dimensions of an image for better responsiveness

Trying to implement this particular design on a responsive website. Wondering if there's a way to establish an inverse resizing technique using jQuery / Javascript so that as the viewport shrinks, the text size increases. Attempted to use jQuery to a ...

Search for a specific node within an Ajax response using jQuery

Struggling with extracting a specific node from an XML document obtained via an Ajax call in my JavaScript code. The returned XML contains key/value pairs, and I am aiming to extract the value linked to a particular key. Let's imagine the structure o ...

Tips for successfully passing a prop to a custom root component in material-ui@next with TypeScript

Is there a way to properly render a ListItem component with react-router Link as the root component? Here's the code snippet in question: <ListItem to="/profile" component={Link} > Profile ...

What could be the reason for my Flask-SocketIO server failing to properly transmit messages to the client-side JavaScript?

I am currently collaborating on a home automation project using raspberry pi3 and flask. My main goal is to send real-time information that can be displayed on a web page (html + javascript). To achieve this, I have incorporated the flask-socketio extensio ...

What strategies can be used to effectively perform a mongo db search that accommodates misspelled terms?

If I search for "wolrd," I would like documents containing "world" to be included in the results. ...

How do I extract data from a JSON or JavaScript array with name/value pairs effectively?

I have a JSON array containing name/value pairs and I am searching for a more efficient way to update the value for a specific name in the array. For example: var myArr = [{"name":"start","value":1},{"name":"end","value":15},{"name":"counter","value":"6"} ...

Using jQuery, eliminate a single value from all drop down options

I am facing an issue where I have multiple drop-downs with the same values. When a user selects "Lunch" from one of the drop-downs, I need to remove "Lunch" from the rest. Below is my code: Frontend code: <?php for($i=1; $i<=7; $i++) {?> <se ...

What is the best way to utilize Enquire.js for dynamically adding and removing CSS classes?

I'm looking to dynamically add and remove a css class based on a media query using Enquire.js but I could use some guidance on utilizing the functions properly. Here's what I envision in pseudo code: if (screens max-width > 480px){ #thumb.r ...

Exporting several functions within a TypeScript package is advantageous for allowing greater flexibility

Currently, I am in the process of developing an npm package using Typescript that includes a variety of functions. Right now, all the functions are being imported into a file called index.ts and then re-exported immediately: import { functionA, functionB ...

Tips for modifying the function of an Electron application using an external JavaScript file

This is the project structure I envision. https://i.stack.imgur.com/ocRp9.jpg kareljs folder houses an Electron app, and upon running npm start within that directory, a window appears and executes the run method of karel.js when the button Run Karel is ...

Utilize ethereumjs-wallet in your web browser as a standalone module

I am looking to generate a wallet (which includes creating an account address and private key) directly in the browser without the need to connect to a node. It seems that in order to utilize web3.js, a provider (such as Metamask or localnode) needs to be ...

Introducing additional choices to the list and automatically refreshing the list with the latest updates

I am currently honing my skills in Yii2 by working on a project using this framework. One of the challenges I am facing is adding new list options dynamically without having to navigate away from the current page. When I click the "Add new option" button ...

Combining actions in a chain within an NgRx effect for Angular

After successfully working on an effect, I now face the challenge of chaining it with a service called in a subsequent action after updating the state in the initial action through a reducer. Here is the effect code: @Effect() uploadSpecChange$: Observab ...

Is it possible to integrate a JavaScript library into the Vue prototype?

I've recently integrated ProgressBar.js library into my app, which is built using vue and laravel with laravel mix. After installing ProgressBar.js via npm install, I am unsure how to incorporate it into my .vue files. I'm considering adding it t ...

Generate a menu submenu allowing for interactive toggling and dynamic visualization of expandable/collapsible sections upon clicking, featuring visually

Looking for assistance in creating a dynamic menu with sub-menus that can expand upon clicking. The goal is to have an expandable menu structure where the user can click to expand or collapse certain sections. However, my current code is not functioning co ...