400 on image upload in bot framework emulator

amit basu 0 Reputation points
2025-11-24T12:59:25.95+00:00

image

When I upload the image hit never reaches to my BotController. what is the issue the error say

{

"error": {

"code": "ServiceError",

"message": "path is not defined"

}

}

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Nikhil Jha (Accenture International Limited) 3,585 Reputation points Microsoft External Staff Moderator
    2025-11-25T08:07:23.6+00:00

    Hello amit basu,

    I understand you are encountering a 400 Bad Request with the specific error {"code": "ServiceError", "message": "path is not defined"} when uploading an image in the Bot Framework Emulator, and the request never reaches your bot's logic.

    The error message "path is not defined" is the standard JavaScript ReferenceError message when code tries to use the path variable (typically the Node.js path module) without importing it first.

    Even though the error appears in the Emulator, the "ServiceError" wrapper indicates that your bot's server caught an unhandled exception during the request processing (likely in the parsing of the file attachment) and returned this formatted error to the Emulator.

    You (or a library you are using) are likely trying to process the uploaded file's metadata (like its name or extension) using the Node.js path module, but the module has not been required at the top of the file.

    Example of problematic code:

    // Missing: const path = require('path');
    // This line will throw "path is not defined"
    const extension = path.extname(attachment.name);
    

    Suggesting a workaround to try:

    1: Check Your Bot Code for Missing Imports

    Search your project files (specifically any files handling file uploads, attachments, or incoming activities) for usages of the word path.

    1. Look for code like path.join, path.resolve, or path.extname.
    2. Ensure that the file containing that code has this line at the very top: JavaScript
         const path = require('path');
      

    2: Check Custom Middleware

    If you are using any custom middleware to handle file uploads (like multer, formidable, or custom logic to save attachments to a temp folder), check those files specifically. The error is happening early in the pipeline, which suggests it's in the code responsible for parsing the incoming HTTP request.

    3: Update Emulator (If the issue is not in your code)

    While less likely to produce this specific error message, ensure you are using the latest version of the Bot Framework Emulator to avoid known issues with attachment payload formatting.

    Note: Would also recommend enable detailed error logging to confirm exactly where this is crashing, you need to see the full stack trace in your bot's console, not just the JSON response.

    Reference:


    Please let me know if adding the missing require('path') resolves your issue. If this answer helps, kindly "Accept the answer" to support the community.


  2. Sina Salam 26,581 Reputation points Volunteer Moderator
    2025-11-26T16:34:11.5666667+00:00

    Hello amit basu,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having ServiceError "message": "path is not defined" while uploading image in bot framework emulator.

    The 400 error and path is not defined message occurs because Emulator v4.15.x breaks file uploads and its new request path hits your server incorrectly. To solve this:

    • Downgrade to Emulator v4.14.1 (file uploads work, controller is hit).
    • Or update your bot to handle the emulator’s /upload endpoint.
    • Alternatively, deploy your bot to Azure and use the DirectLine channel, it uploads via standard /activities with well-documented size limits.

    This clearly distinguishes emulator-specific issues from code bugs. Adding proper logging and verifying your routing ensures your bot catches all image upload attempts reliably. Because, the core issue is an emulator bug in v4.15.x, not your code.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.