File download returns 404 / [object Promise]&target=window after upgrading Mendix 10.23 → 11.0

0
Hello Mendix community,We recently upgraded our application from Mendix 10.23 to Mendix 11.0, and we started experiencing an issue when trying to download files stored as System.FileDocument.ProblemWhen clicking the download icon in our file list, the browser attempts to open the following URL:/[object%20Promise]&target=window This results in a 404 - File or directory not found error.ObservationsFrom debugging in the browser DevTools, the download handler runs the following code:async downloadFile(e) { const n = e.mxobject, a = n.metaData.isRemoteFileEntity; if (!n.get("HasContents") && !a) { return; } const o = await st().getDocumentUrl( n.getGuid(), a ? "" : Ga(n.get("changedDate")), false, a ? undefined : encodeURIComponent(Ga(n.get("Name"))) ); const l = o + "&target=window"; window.open(l, "mendix_file"); } It appears that getDocumentUrl() sometimes returns a Promise-like object, and when concatenated into a string it becomes:[object Promise] which produces the invalid URL.What we already triedCleaned the deployment directoryDeleted deployment/webRebuilt and ran the application locallyDisabled browser cache and hard refreshedConfirmed the same issue occurs both locally and on the serverEnvironmentMendix version: 11.0Previously working version: 10.23File entity: System.FileDocumentFiles are uploaded successfully using mx.data.saveDocument()QuestionHas anyone experienced this issue after upgrading to Mendix 11?Is this related to:a change in the client API (getDocumentUrl)an issue with the generated page bundlesor a known bug in early Mendix 11 releases?Any guidance would be greatly appreciated.Thank you!
asked
2 answers
0

This issue is usually caused by incompatible widgets or outdated Data Widgets after upgrading to Mendix 11. In Mendix 11 some client APIs changed, and older widgets may incorrectly handle the result of getDocumentUrl(), which can lead to [object Promise] being concatenated into the URL.


First, make sure that all Marketplace modules and widgets (especially Data Widgets and file-related widgets) are updated to versions compatible with Mendix 11. After upgrading them, delete the deployment folder and run the application again so the client bundles are regenerated.


If the problem started immediately after the upgrade, it is very likely related to a widget compatibility issue rather than System.FileDocument itself.


If this resolves the issue, please close the topic.


answered
0

Hi Samuel Évora


In Mendix 11, the client runtime moved several APIs to async operations to support the new React-based client and microfrontend architecture Normally Mendix resolves this internally, but older page bundles or widgets compiled with Mendix 10 may still treat it as a synchronous value, which results in the Promise object being concatenated into a string.

You can use the below code:


import { getFileUrl } from "mx-api/data";


async function downloadFile(e) {

const obj = e.mxobject;

const isRemote = obj.metaData.isRemoteFileEntity;


if (!obj.get("HasContents") && !isRemote) return;


// Prefer the new API in Mx 11

const url = await getFileUrl({

object: obj,

// Optional: keep server name if you want to control the download name

fileName: isRemote ? undefined : encodeURIComponent(obj.get("Name")),

// thumbnail: false // default

});


window.open(`${url}&target=window`, "mendix_file");

}


basically you have to get the getfileurl from import[Mendix 11 Client API Documentation mx-api/data] or else try the below code


// Put this at the top of your JS action file (or inside BEGIN EXTRA CODE)

import { getFileUrl } from "mx-api/data"; // Mx 11 client API

// If this is inside a generated JS action, ensure "import 'mx-global';" is present at file top.


async function downloadFile(e) {

const obj = e.mxobject;

const isRemote = obj?.metaData?.isRemoteFileEntity;


// Respect HasContents for local files; remote files may not have HasContents set

if (!obj.get("HasContents") && !isRemote) return;


// Optional: preserve the server-side download name (Mx will set the Content-Disposition)

// Avoid double-encoding: pass the raw name; Mendix handles header encoding.

const fileName = isRemote ? undefined : obj.get("Name");


// Mendix 11: getFileUrl is async and returns Promise<string>

const url = await getFileUrl({

object: obj,

fileName, // optional; omit for remote entities

// thumbnail: false // default

});


window.open(`${url}&target=window`, "mendix_file");

}


Will work. If not let me know I can help you.

answered