The link containing special characters like % cannot access the api

I am facing an issue with retrieving a signUrl from S3. When I make the call with special characters like %, my code does not parse it correctly and I receive a 404 not found error.

Here is the ajax request I am using:

My API setup:

app.get('/website/api/admin/get-signed-url/thumbnail/:key/:type', auth.getMember, directives.noCache, getThumbnailSingedUrl);

The function being called:

function getThumbnailSingedUrl(req, res) {

    if (!isAdmin(req, res)) {
        return;
    }

    var key = req.params.key || '';
    var type = req.params.type || '';

    ThumbnailBucketFacade.getSignedUrl(
        'putObject',
        key,
        type,
        function onGotSignedUrl(error, result) {
            if (error) {
                RestResponse.serverError(res, error);
            } else {
                RestResponse.ok(res, result);
            }
        }
    );
}

Interestingly, the call works fine in a dev environment but not when special characters like % are involved.

Strangely, the same code works perfectly in a different project without any issues.

Any suggestions or ideas to resolve this?

Answer №1

I think the data you're dealing with is encoded as a URI. Therefore, it would be necessary to decode it first before using it:

const key = req.params.key && decodeURIComponent(req.params.key) || '';
const type = req.params.type && decodeURIComponent(req.params.type) || '';

To learn more about decoding URIs, click here.

This process is also compatible with older versions, so there's no need to worry about corrupting a plain string.

Answer №2

After some investigation, it turned out that the problem was caused by a misconfiguration in 'nginx', the web server.

The configuration in 'nginx' was set to automatically add a '/' at the end of the site name. This caused confusion with other slashes and resulted in the call not being recognized.

A big thank you to those who assisted in solving this issue!

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

Unable to locate the package '/apollo-server-express/' that has been imported in the `server/index.js` file

I'm encountering an issue while attempting to launch my express server on my digital ocean droplet. After executing npm install, I try running npm run startServer but encounter the following error: Error [ERR_MODULE_NOT_FOUND]: Cannot find package &ap ...

Google Extension PHP Plugin

Is it feasible to integrate a PHP file into a Google Extension for Chrome? I've been exploring the idea of creating an extension and most resources only mention HTML, CSS, and JavaScript. Any guidance on using PHP in the extension would be highly valu ...

Download files from Firebase storage to a user's device

I have a variety of files such as images, videos, and audio stored in my firebase storage. My goal is to provide users with the ability to download these files to their computers by clicking on a download button. After reviewing the firebase documentation ...

Guide on locating an element inside its parent using Puppeteer

When using cypress, I am able to locate child elements within other elements like this: cy.get('div#Login_form).within(() => { cy.get('input[name="human[email]"]').type('John') cy.get('input[name="human[password]"]&apo ...

Issue - The module ./en.json could not be located when using the vue-i18n plugin

I recently integrated the i18n plugin into my existing Vue project to add localization. After following all the installation instructions from various sources (such as here), I made sure that each locale has its own file under /src/locales with the correct ...

One array comprises of all elements found in a separate array

After grappling with this problem for a while, I still haven't been able to find a solution. If I have 2 arrays structured like this: array1 = [ { name: 'John', age : 25}, { name: 'Jane', age : 58} ] array2 = [ { name: ...

Determine the position of the cursor in an editable span

Is there a way to add text at the cursor position in an editable span when a button is clicked? The span contains multiple lines of text and HTML tags. [Take a look at this example on JSFiddle](http://jsfiddle.net/8txz9sjs/) ...

Issue with iPhone CSS displaying differently on mobile devices

The CSS design does not display correctly on iPhone devices in real-life testing, even though it appears fine on browsers with mobile view emulators. Interestingly, the design also looks great on Android phones but encounters issues specifically on iPhones ...

An issue arose while trying to create the perfect seed with yeoman

While working on my first Yeoman webapp using the ultimate-seed-generator, I encountered some errors that are hindering progress: C:\Users\Fidel\Desktop\Nueva carpeta\new-proyect>npm install > <a href="/cdn-cgi/l/email ...

Customized slider in jQuery UI allowing users to select height using a scaled ruler

Currently, I am tackling a challenging math problem related to adjusting the height selector input. Essentially, I have implemented a jQuery UI slider for choosing a height. It operates in inches and ranges from 0 to 120 (equivalent to 10 feet in height). ...

What is the reason behind Node.js Express invoking the "close" method on POST requests with data before finalizing the request closure?

I have developed a streaming server using Node.js and Express to send data in chunks through a POST endpoint. However, I've noticed that the request close event is being triggered as soon as there is data in the request, even though I have not explici ...

Steps to avoid IE11 prompt (Do you really want to leave this site)

In the midst of making a webpage, I find myself faced with the peculiar issue of only having a dropdown to select. To make matters worse, when attempting to navigate to the next page in IE11, a pesky message pops up. Curious about the default behavior of ...

Conceal the div element if the value exceeds 0

I'm looking for a way to display a div when the number of remaining days is less than 0. I got it working on jsfiddle, but for some reason, it doesn't work anywhere else. if ($('.daysrem&a ...

How can I send a file and a string request using the POST method to a Spring REST controller that accepts byte[] and Strings with Angular

Need help with sending a post method that includes a file and another string request parameter to a spring rest controller using angular. The server controller parameter is set up to receive an array of bytes for the file and another string request wrappe ...

What is the best way to organize and group messages in JavaScript in order to push them to a subarray?

Having trouble coming up with a name for this question, but here's the issue I'm facing: I currently have an array in PHP containing several entries. Array ( [0] => stdClass Object ( [sender_id] => 0 [me ...

What could be the reason for e.target.value being undefined?

Can someone explain why e.target.value is returning undefined when logged to the console in this simple component? The value should be defined within the element, so I'm confused as to why e.target is not giving the correct value. const NavBar = () = ...

Exploring the power of ES6 Generator functions in conjunction with SailsJS

Utilizing generators in nodejs is a game changer for me. They really enhance the server-side feel of my code. I've been experimenting with incorporating generators into my Sails app. Here's an example where my controller successfully works when I ...

Transforming Node's loops into asynchronous functions

I have the following sync function: for (var i = 0; i < results.length; i++) { var key1 = results[i]['__key']; for (var j = i + 1; j < results.length; j++) { ...

Heroku - JavaScript and CSS Updates Causing Loading Issues

Ruby version: 2.1.5 | Rails version: 4.1.1 For some reason, the changes I make to my JavaScript and CSS files are not reflecting on Heroku; it seems like the cached assets are still being used. I've tried removing the assets and precompiling them bef ...

"Having access to the source code of third-party JavaScript libraries can greatly aid in the debugging

Is it possible to access the source code of third-party JavaScript libraries for debugging purposes? I work with npm/nodejs and the angular CLI, which uses Webpack. The libraries I am interested in having access to during debugging are: Angular 2 (Type ...