# Can't get import url working

**URL:** <https://community.transloadit.com/t/cant-get-import-url-working/15369>\
**Category:** Uppy\
**Created:** [July 23, 2020, 10:25pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369 "2020-07-23T22:25:48Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robing](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robing](https://community.transloadit.com/u/robing)\
**Post date:** [July 23, 2020, 10:25pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/1 "2020-07-23T22:25:48Z")

</div>

Hello!

I’m trying to use Uppy to upload remote urls. It properly import url details (file name, size, etc.), but when I am clicking on the upload button I see the message “Upload failed” and the error message “Could not post companion/url/get. Error: Failed request with status: 404. Not found message: Not found”.

I configured the latest version of the companion using the official example from [https://github.com/transloadit/uppy/blob/master/examples/uppy-with-companion/server/index.js](https://github.com/transloadit/uppy/blob/master/examples/uppy-with-companion/server/index.js)  
My server code looks exactly the same as index.js

I see that the example code has only the route definition:

// Routes  
app.get(’/’, (req, res) =\> {  
res.setHeader(‘Content-Type’, ‘text/plain’)  
res.send(‘Welcome to Companion’)  
})

Should I add the code to process POST requests to the route ‘companion/url/get’? I’ve checked all documentation related to the companion and can’t find anything related to this issue.

My client code (index.html):

```
uppy = Uppy.Core({
        debug: false,
        autoProceed: false,
        restrictions: {
          maxNumberOfFiles: 5,
          minNumberOfFiles: 1
        }
}).use(Uppy.Dashboard, {
      inline: true,
      showProgressDetails: true,
      showLinkToFileUploadResult: false,
      proudlyDisplayPoweredByUppy: false,
      target: '#drag-drop-area'
    })
  .use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: 'http://localhost:3000/' })
  .use(Uppy.Tus, {endpoint: 'http://localhost:3000/files/'});

```

Please help me in this issue.

---

<div class="post-metadata">

**Author:** ![ajkachnic](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/ajkachnic/32/260_2.png) [@ajkachnic](https://community.transloadit.com/u/ajkachnic)\
**Post date:** [July 25, 2020, 11:40pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/2 "2020-07-25T23:40:06Z")

</div>

This is a strange issue. I’ve tested companion in the past and not had any problems, but come to think of it, I haven’t tested it with importing from URLs. I’m now going to test this out and see if it works for me. Just thought I’d update you beforehand.

I should be able to help with this, after I see how it works for me

- Andrew

---

<div class="post-metadata">

**Author:** ![ajkachnic](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/ajkachnic/32/260_2.png) [@ajkachnic](https://community.transloadit.com/u/ajkachnic)\
**Post date:** [July 25, 2020, 11:52pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/3 "2020-07-25T23:52:10Z")

</div>

Okay so after some quick testing, the URL upload was working perfectly fine.

I think that it may be an incorrect port or a port conflict. From the code you are posting, it appears that you are trying to run Companion and Tus on the same port, or you have the incorrect port set for Companion.

Based on the example server code you are using, Companion should be on port `3020`, rather than `3000`. I normally wouldn’t question this except for the fact that you have Tus and Companion on the same port

If this is the error, you can probably fix the issue by replacing

```javascript
  .use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: 'http://localhost:3000/' })

```

With

```auto
  .use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: 'http://localhost:3020/' })

```

Let me know if this worked. Best wishes

- Andrew

---

<div class="post-metadata">

**Author:** ![robing](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robing](https://community.transloadit.com/u/robing)\
**Post date:** [July 26, 2020, 2:06pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/4 "2020-07-26T14:06:24Z")

</div>

Dear Andrew,  
Thank’s a lot for your help.  
I’ve tried to change the port, but the error is the same.  
It seems I have diffuculties with Tus and Uppy Companion.  
Could you please explain how to use Tus and Companion together on the server side? I’m not familiar with Node JS.  
Because now I’m trying to combine it with my Django app written in Python.  
What I have:

1. for Tus I use Python library [pypi.org/project/tus/](http://pypi.org/project/tus/) And it works OK for file uploads (Tus + Uppy). The Tus endpoint is http:// my\_server\_ip /files (port 80)
2. I’ve installed and configured Node.JS and created the companion file companion.js. Please see the full code of companion file below. It’s listening the port 3020.
3. In my Apache2 configuration I have  
ProxyPass /companion [http://localhost:3020](http://localhost:3020)  
so I simply redirect all companion requests from http:// my\_server\_ip /companion to the companion server running under NodeJS (http:// localhost:3020).

and I see it works for url fetching. Companion can get details about urls that should be downloaded. And the endpoint http:// my\_server\_ip /companion works. But when I try to download files uppy checks the url http:// my\_server\_ip /companion/companion/url/get and failed (it doesn’t exists).

What I don’t understand:

1. What is ‘/companion/url/get’ route? I don’t see the implementation of this in companion example. It  
only has:

app.get(’/’, (req, res) =\> {  
res.setHeader(‘Content-Type’, ‘text/plain’)  
res.send(‘Welcome to Companion’)  
})

and of course when my app checks ‘/companion/url/get’ it doesn’t exist. It returns

// handle 404  
app.use((req, res, next) =\> {  
return res.status(404).json({ message: ‘Not Found’ })  
})

1. How to run Tus and Companion both on NodeJS backend? Where I can find full example or tutorial? Maybe if I delete Tus implementation on Python and run all things (Tus, Companion) on NodeJS it will work.

Here is the full code of companion.js

const express = require(‘express’)  
const companion = require(’…/…/node\_modules/@uppy/companion’)  
const bodyParser = require(‘body-parser’)  
const session = require(‘express-session’)

const app = express()

app.use(bodyParser.json())  
app.use(session({  
secret: ‘some-secret’,  
resave: true,  
saveUninitialized: true  
}))

app.use((req, res, next) =\> {  
res.setHeader(‘Access-Control-Allow-Origin’, req.headers.origin || ‘\*’)  
res.setHeader(  
‘Access-Control-Allow-Methods’,  
‘GET, POST, OPTIONS, PUT, PATCH, DELETE’  
)  
res.setHeader(  
‘Access-Control-Allow-Headers’,  
‘Authorization, Origin, Content-Type, Accept’  
)  
next()  
})

// Routes  
app.get(’/’, (req, res) =\> {  
res.setHeader(‘Content-Type’, ‘text/plain’)  
res.send(‘Welcome to Companion’)  
})

// initialize uppy  
const uppyOptions = {  
providerOptions: {  
drive: {  
key: ‘your google key’,  
secret: ‘your google secret’  
},  
instagram: {  
key: ‘your instagram key’,  
secret: ‘your instagram secret’  
}  
},  
server: {  
host: ‘localhost:3020’,  
protocol: ‘http’  
},  
filePath: ‘/var/www/uploads/’,  
secret: ‘some-secret’,  
debug: true  
}

app.use(companion.app(uppyOptions))

// handle 404  
app.use((req, res, next) =\> {  
return res.status(404).json({ message: ‘Not Found’ })  
})

// handle server errors  
app.use((err, req, res, next) =\> {  
console.error(’\x1b[31m’, err.stack, ‘\x1b[0m’)  
res.status(err.status || 500).json({ message: err.message, error: err })  
})

companion.socket(app.listen(3020), uppyOptions)

console.log(‘Welcome to Companion!’)  
console.log(`Listening on 3020`)

---

<div class="post-metadata">

**Author:** ![ajkachnic](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/ajkachnic/32/260_2.png) [@ajkachnic](https://community.transloadit.com/u/ajkachnic)\
**Post date:** [July 26, 2020, 2:32pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/5 "2020-07-26T14:32:42Z")

</div>

Hello. Thanks for your fast response. I haven’t tried to run this exact setup, with Apache, Tus, and Companion, but I still have some insights

1. First of all, the `/url/get` is a route defined when you pass your express server instance to companion (it’s defined [here](https://github.com/transloadit/uppy/blob/master/packages/%40uppy/companion/src/server/controllers/url.js#L13) in the source code).  
When you run `companion.socket(app.listen(3020), uppyOptions)`, that modifies `app`, adding a bunch of routes that aren’t in the docs, because they are part of the way companion works, and usually not an issue

2. Ideally, you’d run Tus and Companion on two seperate public ports, and this may be the cause of the issue. It’s also worth noting that the `tus-node-server` is deprecated, and [`tusd`](https://github.com/tus/tusd) is the recommended way to use Tus

The fetching of `http://server_ip/companion/companion/url/get` doesn’t make any sense, as it should in this case be getting `http://server_ip/companion/url/get`. The normal route would be `/url/get`, but since there is some rerouting going on, that is not the case

I think the issue has something to do with rerouting your Companion to `http://server_ip/companion` and also something with your Uppy config

Can you send a code snippet of where you initialize the `Url` plugin?

_By the way, you can send a code block by placing ``` one line above and below your code_

- Andrew

---

<div class="post-metadata">

**Author:** ![robing](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robing](https://community.transloadit.com/u/robing)\
**Post date:** [July 26, 2020, 9:35pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/6 "2020-07-26T21:35:08Z")

</div>

Hi,again.

> [@ajkachnic](#):
>
> The fetching of `http://server_ip/companion/companion/url/get` doesn’t make any sense, as it should in this case be getting `http://server_ip/companion/url/get` . The normal route would be `/url/get` , but since there is some rerouting going on, that is not the case

I’ve added the screenshot with details. I try to call the companion via curl and it worked for GET [http://localhost:3020](http://localhost:3020), but can’t POST/GET to [http://localhost:3020/companion/url/get](http://localhost:3020/companion/url/get) .

> [@ajkachnic](#):
>
> Can you send a code snippet of where you initialize the `Url` plugin?

I use CDN bundle. So on the frontend I have:

\< link href=“[https://transloadit.edgly.net/releases/uppy/v1.19.0/uppy.min.css](https://transloadit.edgly.net/releases/uppy/v1.19.0/uppy.min.css)” rel=“stylesheet”\>  
\< script src=“[https://transloadit.edgly.net/releases/uppy/v1.19.0/uppy.min.js](https://transloadit.edgly.net/releases/uppy/v1.19.0/uppy.min.js)”\>

```
uppy = Uppy.Core({
        debug: false,
        autoProceed: false,
        restrictions: {
          maxFileSize: parseInt($("#max-filesize").attr('name')),
          maxNumberOfFiles: 5,
          minNumberOfFiles: 1
        }
}).use(Uppy.Dashboard, {
      inline: true,
      showProgressDetails: true,
      height: 300,
      showLinkToFileUploadResult: false,
      proudlyDisplayPoweredByUppy: false,
      target: '#drag-drop-area'
    })
  .use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: '/companion' })
  .use(Uppy.Tus, {endpoint: '/files/'});

```

 ![uppy](https://canada1.discourse-cdn.com/flex032/uploads/transloadit/original/1X/5612c346b363973280d91ef858208e94a82631d7.png)

---

<div class="post-metadata">

**Author:** ![robing](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@robing](https://community.transloadit.com/u/robing)\
**Post date:** [July 26, 2020, 10:12pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/7 "2020-07-26T22:12:12Z")

</div>

It seems the issue was:

.use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: ‘/companion’ })

I should use the full path

.use(Uppy.Url, { target: Uppy.Dashboard, companionUrl: ‘http://my\_server\_ip/companion’ }).

But now I have the error:

uppy.min.js:1 WebSocket connection to ‘ws://my\_server\_ip/companion/api/711afa45-051b-4099-b249-b3fc8093256d’ failed: Error during WebSocket handshake: Unexpected response code: 404

It looks like I solved one issue but ran into another. Here are messages from log on the companion side:

companion: 2020-07-26T22:22:19.909Z [debug] URL file import handler running  
companion: 2020-07-26T22:22:19.944Z [debug] Instantiating uploader.  
companion: 2020-07-26T22:22:19.946Z [debug] Waiting for socket connection before beginning remote download.  
companion: 2020-07-26T22:22:19.946Z [debug] fda6eba0 uploader.socket.wait waiting for connection

---

<div class="post-metadata">

**Author:** ![ajkachnic](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/ajkachnic/32/260_2.png) [@ajkachnic](https://community.transloadit.com/u/ajkachnic)\
**Post date:** [July 28, 2020, 3:14pm UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/8 "2020-07-28T15:14:08Z")

</div>

Hello again. It appears that for some reason, Companion’s websocket is not running. The websocket is utilized for giving progress updates.

From what I can tell, within the inner workings of Companion, upon an upload, it generates a token and returns that to the client from the `/url/get` route. From there, the client attempts a connection at `/api/<token>`. This 404 error is caused by that route not existing for some reason.

What happens if you attempt this with a different provider? Does the issue persist even with a different provider?

From what I can tell, the first part of the token in the route (`711afa45`) should be the same as the debug output (`fda6eba0`). For some reason, there’s a token mismatch. What happens if you attempt the upload again?

- Andrew

---

<div class="post-metadata">

**Author:** ![Saccarab](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/saccarab/32/347_2.png) [@Saccarab](https://community.transloadit.com/u/Saccarab)\
**Post date:** [January 21, 2021, 10:18am UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/9 "2021-01-21T10:18:41Z")

</div>

Hi,

I think I am experiencing the exact same issue.

In my case, the first upload attempt on a browser session will work for each provider but for any subsequent request for the same provider Uploader on the companion instance will not instantiate and will hang on the below line.

> <https://github.com/transloadit/uppy/blob/main/packages/@uppy/companion/src/server/controllers/url.js#L66>

> [@Uppy - Companion - Google drive - Socket- Emitter never fires](https://community.transloadit.com/t/uppy-companion-google-drive-socket-emitter-never-fires/15187/2):
>
> Hello! This seems to be an issue with Companion’s token being out of sync with the token that your browser is trying to access. There is a similar issue [here](https://community.transloadit.com/t/cant-get-import-url-working/15369/8) Can you open your network tab in the devtools and send a screenshot after attempting to upload? That should help us look further into this issue. Thanks - Andrew

So it probably is actually a token mismatch similar to the above issue, any information on how to debug this would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![mkgn](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.transloadit.com/mkgn/32/1197_2.png) [@mkgn](https://community.transloadit.com/u/mkgn)\
**Post date:** [August 8, 2024, 3:58am UTC](https://community.transloadit.com/t/cant-get-import-url-working/15369/10 "2024-08-08T03:58:07Z")

</div>

This still doesn’t work even in the example at : [Uppy](https://uppy.io/examples/) The url i gave was [Bonsai, Kenshin Toge - Bonsai - Wikipedia](https://en.wikipedia.org/wiki/Bonsai#/media/File:Bonsai,_Kenshin_Toge.jpg) My local configuration also giving the same error. My configuration is similar to what is described in this thread.
