Having trouble uploading a file with Parse.File in an express web application

Currently, I am developing an express web application with a Parse backend. To render webpages, I am utilizing .ejs files. Upon clicking the submit button on the file upload form, Express routes me to testfile.js where I am using the Parse.File method to upload the file to the Parse database. However, I suspect there might be an issue with my function that extracts the file from the submitted form. I have attached both testfile.js and the .ejs file containing the upload form for your review. Please take a look and provide suggestions for the correct solution.

exports.xmlfile = function(req, res) {
var filecontrol = $("#myfile")[0];
var file= filecontrol.files[0];

var parseFile= new Parse.File("8706388_orig.jpg",file);
parseFile.save().then(function(){
var newobj= new Parse.Object;
newobj.set('file', parseFile);
newobj.save();
res.redirect('/administrator');
});
};

This is the upload form in the .ejs file:

<form class="form form2" id="myform" name="myform" enctype="multipart/form-data"    method="post" action="/administrator">
      <input type="file" id="myfile" name="myfile">
      <input class="w-button upload" type="submit" value="Upload" >
    </form> 

Answer №1

It appears that you are correctly saving the file, however, the object you are attempting to link it to is not properly declared.

Following the common practice outlined in the documentation, it is recommended to first declare your class and then create an instance of it. For example, if your class is named "Bar":

var Bar = Parse.Object.extend("Bar");
var bar = new Bar();
bar.set("file", parseFile);

Lastly, it is important to ensure that you wait for the save operation to complete before redirecting:

bar.save().then(function() {
    res.redirect("/dashboard");
});

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

Managing multiple arrays in asynchronous functions in node.js

I am facing an issue with a large array (10K) that I need to split. I tried following this method: and it worked perfectly. However, I now need to pass the separated arrays to a request function and await the response before passing it to savetodb. Could ...

The ngModel directive automatically clears the checkbox's Checked status

Currently, my Angular code is set up to validate a checkbox using ng-model: <input type="checkbox" name="news1" value="news1" ng-model="news" <c:if test="${xxxx == yes'}">checked="checked"></c:if>> <label ng-click="news1();"&g ...

"Alert box displaying error message is not appearing on the screen

In order to display an error message using a tooltip, I have hidden the tooltip by setting the style of a span with an id of demo to display:none. Then I use JavaScript's getElementById method to retrieve the value of the input field with an id of use ...

Performing a sequence of actions using Jquery Queue() function and iterating through each

I am facing an interesting challenge with an array called result[i]. My goal is to iterate through each field in the array and add it to a specific element on my webpage. $("tr:first").after(result[i]); However, I would like this process to happen with a ...

Comparing $.fn.fancybox and $.fancybox: What sets them apart?

I'd like to understand the distinction between the two items shown above. In what ways do they differ from each other? ...

Exploring Next.js: A Guide to Implementing Browsing History in Your Application

Struggling to add entries to browser history when using Next.js's Link property for page navigation. Unable to push history entry, leading to incorrect page location in my application when going back. Any ideas on implementing this feature in Next.js? ...

Encountering NotFoundHttpException with Jquery Ajax in Laravel 4

Hello everyone! I'm diving into the world of ajax and currently experimenting with sending form input to a controller through a route and then displaying it in a div. Unfortunately, I've hit a roadblock as I keep getting a NotFoundHttpException ...

How can I make Backbone.js execute a function following the creation of a Collection?

It seems like I may not be grasping the full picture here, but let me lay out my current understanding: I have a Model that holds 'all' the data (JSON retrieved from a single URL). This model contains one or more Collections which are populated ...

Unusual outcome observed when inputting a random number into HTML using JavaScript

In my HTML file, I am trying to input a number within 50% of a target level into the "Attribute" field. Here is the code: <!DOCTYPE html> <html> <body> <input type = "number" name = "playerLevel" onchan ...

trouble encountered when attempting to integrate typeahead functionality in AngularJS using jQuery

Greetings! I am brand new to using AngularJS and currently exploring the implementation of typeahead functionality. I decided to utilize an existing library by including the following script: <script src="lib/xyz/typeahead.bundle.js"></script> ...

Why isn't this code for hiding the animation and displaying it not functioning properly?

Why isn't this animation from display none to block working properly? The initial code appears as follows, and it functions correctly: $(".box_outer").stop().animate({top: '25px' , opacity: 1}, 100); When I add display: none; to the class ...

Locate a specific document using its object ID within a MongoDB collection using Node.js and Express.js

Hey, I'm having trouble fetching the products of a specific user. I added the user's Object ID in the model, but I'm stuck on how to set up the router callback function! { "_id": { "$oid": "62f250d3e2533c ...

Is there an implicit transformation or action involved when the promise chain is resolved or rejected in $q?

Is there an intrinsic digest/apply included when the promise chain is resolved/rejected in $q? I recently switched from using $q to q in my code and it seems like a digest is no longer happening, leading to different outcomes. What could be causing this c ...

Real-time changes may not be instantly reflected in the model update

I need to add two numbers together and display the sum in a third input field: HTML <div ng-app="myApp"> <div ng-controller="MainCtrl as mainCtrl"> Main {{mainCtrl.foo}} <br/> <input type="text" ng-model="mainCtrl.foo"/> ...

Utilizing a child component in React to trigger a function on its sibling component

Trying to put this question into words is proving to be a challenge. I am wondering in React, if there is a way for a child component that is deeply nested (2 levels deep from the parent) to trigger a function on another component that it has a sibling rel ...

Only the initial element within the specified class is targeted by JQuery

Currently, I am utilizing Kendo UI to refresh multiple charts by class without having to access each one individually. Here is the code snippet I am using: $(".k-chart").data("kendoChart").refresh(); The issue I am encountering is that only the first cha ...

Encountered an error loading resource: server returned a 400 (Bad Request) status when using Angular with NodeJS

My Angular and NodeJS application with Express (v4.17.1) exposes a REST API like this: app.get('/myRestApi', function (req, res) { console.log('here you are ... '); res.end('success!\n'); }); The body of this API ...

The module demoApp could not be instantiated because of an error stating that the module demoApp is not accessible

I am struggling to create a basic Single Page Application (SPA) using Angular and ngRoute/ngView. Unfortunately, I can't seem to get it to work properly. Every time I try, I encounter the error: angular.js:68 Uncaught Error: [$injector:modulerr] Fail ...

Create an interactive visualization using d3.js

Currently, I am on the hunt for a technology that can help me render a tree structure based on Json data. After researching options like graphViz and d3, it seems like d3 is more optimized for modern browsers. With the extracted Json data, my goal is to c ...

Putting retrieved data from firebase into an array using Angular and Firebase format

Hey everyone, I'm currently facing an issue with formatting my Firebase data into an array. Below is the service where I am retrieving data from Firebase: File name: subcategory.service.ts export class SubcategoryService { subcategoryRef: Angula ...