Possibile to upload an object from pc

Is there a possibility of loading an object directly from the pc in the network room without uploading it on any other server?
It works locally but not when the app is deployed.

Hi Saad,

Loading an object directly from your PC in a deployed application typically requires rallying around the limitations of web browsers, which restrict local file access for security reasons. When running locally, it works because the application has access to local files.

In a deployed environment, you usually must upload files to a server or an accessible URL. However, to work around this:

  1. Local Testing: When you run the app locally, ensure that you use HTTPS if you’re testing file uploads; otherwise, browsers might restrict this functionality in production.

  2. File Uploading: The system that allows users to upload files to the server might require backend handling. Once a file is uploaded, the system needs to manage state updates accordingly.

  3. Drag-and-Drop Files Collection: You could implement a drag-and-drop interface where files dropped within your 3D space are added to the scene, as seen in the DropListener example from your files. It allows users to drop files that can then be processed.

  4. Use of Web Server: Consider running a local web server (like using http-server in Node.js or a live server with Visual Studio Code). This way, files can be accessed without needing to upload them somewhere.

  5. Network Configuration: Ensure your network configuration allows connections to your backend service where files might be uploaded or retrieved.

Here’s an example code snippet demonstrating how to drop files into the scene:

import { DropListener, DropListenerEvents } from "@needle-tools/engine";

const dropListener = new DropListener();
gameObject.addComponent(dropListener);

dropListener.on(DropListenerEvents.FileDropped, async (evt) => {
   const file = evt.detail as File;
   const result = await addFile(file, context); // Process the file when dropped
   if (result) {
       console.log("File loaded:", result);
   }
});

Make sure you handle the uploading functionality for deployed versions, as running it from the file URL will likely not work.

If this does not address your issue, please provide the environment specifics about your deployment setup and possibly the backend configuration.

3 replies left
thread_jQOS8xnYUjEGRvfmmQRQRQcc
Reply to this message to continue the conversation

This topic was automatically closed 13 days after the last reply. New replies are no longer allowed.