Permissible File Formats for Uploading via Ajax

I'm seeking assistance with a query regarding file uploads on a server using the AjaxFileUpload tool. I specifically want to restrict certain file types from being uploaded, and although there is server-side validation in place, I am looking to validate the file types on the client side.

I attempted to use the AllowedFileTypes method of the upload tool as follows:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" OnUploadComplete="OnUploadComplete" ThrobberID="Throbber" ClientIDMode="AutoID" AllowedFileTypes="jpg,pdf,docx" />

However, it seems to only allow pdf files to be uploaded while rejecting jpg and docx formats. I'm unsure if this issue is due to a bug within the AjaxFileUpload tool itself.

Are there alternative methods to achieve this? I've implemented some javascript code to handle the file type validation:

var validFilesTypes = ["docx", "jpg", "pdf"];
function ValidateFile() {
  var file = document.getElementById("<%=AjaxFileUpload1.ClientID%>");
  var label = document.getElementById("<%=lblStatus.ClientID%>");
  var path = file.valueOf;
  var ext=path.substring(path.lastIndexOf(".")+1,path.length).toLowerCase();
  var isValidFile = false;
  for (var i=0; i<validFilesTypes.length; i++) {
    if (ext==validFilesTypes[i]) {
        isValidFile=true;
        break;
    }
  }
  if (!isValidFile) {
    label.style.color="red";
    label.innerHTML="Invalid File. Please upload a File with" +
     " extension:\n\n"+validFilesTypes.join(", ");
  }
  return isValidFile;
}

I have adjusted the AjaxFileUpload configuration according to the script above, but unfortunately, it's not achieving the desired outcome:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" OnUploadComplete="OnUploadComplete" OnClientUploadComplete="ValidateFile" ThrobberID="Throbber" ClientIDMode="AutoID" />

Answer №1

The AjaxFileUpload feature supports the following file types:

<ajaxToolkit:AjaxFileUpload ID="AjaxFileUpload1" OnUploadComplete="AjaxFileUpload1_UploadComplete" runat="server" AllowedFileTypes="jpeg,jpg,png,gif,pdf,zip,rar,ZIP,RAR" MaximumNumberOfFiles="5" />

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

Tips on customizing regex to selectively identify specific strings without capturing unrelated ones

Currently, I am working with this regex: /(?<=^|\/)(?:(?!\/)(?!.*\/))(.*?)[:-]v([\d.-]+)(?=\.|$)/ The goal is to extract the captured group from the following strings: rhmtc/openshift-velero-plugin-rhel8:v1.7.9-4 oc-mirror-plug ...

What causes an infinite loop in my app when passing a prop, and why doesn't it update the prop as expected?

Trying to pass a single variable from one component to another should be simple, but it's turning out to be more complicated than expected. I have a Search bar in one component and I want the input from that search bar to display in another component. ...

Header Express does not contain any cookies, which may vary based on the specific path

In my express.js app, I have two controllers set up for handling requests: /auth and /posts. I've implemented token authorization to set the Authorization cookie, but I'm encountering an issue when making a request to /posts. The request goes th ...

Obtaining a group object when the property value matches the itemSearch criteria

What is the best way to extract specific objects from a group when one of their properties has an array value, specifically using _.lodash/underscore? { "tileRecords" : [ { "tileName" : "Fama Brown", "tileGroup" : ["Polished", "Matt", ...

Remove the session variable when a JavaScript function is triggered

After creating a function called destroy(), I have set it to be called on the onclick event of the logout button. However, the issue is that the server-side code within that function is always executed when the page loads, regardless of whether the logou ...

Using AJAX to send an array as a response from Laravel

After implementing Laravel to handle an AJAX post request, I encountered an issue with displaying the route data. public function infoRoute(Request $request) { // Extracting required information $ship_id = $request->ship_id; ...

Tips for accessing a file in AngularJS

Can AngularJS be used to read files? I am interested in placing the file within an HTML5 canvas for cropping purposes. I was considering implementing a directive. Below is the JavaScript code that I plan to include in my directive: function readURL(input ...

Using a for loop in conjunction with Observable.forkJoin

In my component, I am striving to populate an array known as processes, containing individual process objects that each have a list of tasks. Currently, I am dealing with two API calls: /processes and /process/{processId}/tasks I utilize the /processes ...

Is it possible to retrieve the index of a chosen v-select option within Vuetify?

Exploring Vuetify for the first time, I'm encountering an issue with obtaining the index of a selected option on the v-select component. My goal is to populate a text field based on the option that is clicked once I have the index. I am fetching an ...

Must initiate a restart of the Next.js development server in order to see the updates reflected

Starting with another query, reference #71649994, essentially poses a similar question. However, in my scenario, this issue persists across all projects I have created, unlike the mentioned case where it only affects one project. As no resolution was provi ...

Retrieve and store an array from a JSON response using jQuery

Appreciate the assistance in advance. I am currently working with a plugin that requires a JSON response to be formatted as an array instead of an object. Below is a snippet of the JSON response I am receiving: { "instruments": [ { ...

Troubleshooting a malfunctioning AJAX function in CakePHP 2.x

I am currently learning cakephp and experimenting with incorporating AJAX functionality into my project. Within the view file add.ctp, I have included the following code: $('#office_type').change(function(){ var office_id = $('#office_ ...

Utilizing ajax/jquery for form verification in Joomla

I am interested in developing custom form validation on Joomla using either ajax or jQuery. When a user inputs something invalid and moves away from the input field, it should be validated and display an error message. Additionally, all error messages wi ...

Is combining form and fieldset causing issues?

My <form> for uploading an image and my <fieldset> for sending data via AJAX both work individually. However, when I try to merge them into one form, things get complicated. This is being done on a Node.JS server. Upload <form>: <for ...

How can an array be transferred from app.get() to app.post()?

I am receiving an array from an ajax file that contains a list of products which I need to add to the order. My goal is to link the table of orderProducts and the order table together using a column called orderId. However, I am having trouble getting the ...

What is the process for combining JSON objects using the "id" key as the basis for merging

Having this json structure, my goal is to merge it based on the articleId. [{ "articleId": "45", "isA": false, "flags": { "isDema": fals ...

Browser Compatibility in Three.js

Could someone assist me with activating webgl on Internet Explorer version 8? I am able to use Firefox and Chrome without any issues. Your help would be greatly appreciated. ...

Can you explain the significance of the role attribute being set to "button"?

While browsing through the Google+ Project's page, I noticed that all the buttons were created using div elements like: <div role="button"></div> I'm curious to know if this is done for semantic reasons or if it has an impa ...

Using NextJS to pass a parameter to an onClick function

I've been using the react-simple-star-rating package in this sample code. However, I'm facing an issue: Within my trains parameter, there is a variable id that I would like to pass to the handleRating function using onClick, but I can't see ...

What is the best way to transfer the JWT token from the server to the client using an HTTP header?

I have been searching for an answer on how to pass the JWT Token from the client to the server securely, but I am not satisfied with the explanations I found. Everyone talks about the most secure way to transfer the JWT token using HTTP headers instead of ...