question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extension on upload doesnt show

See original GitHub issue

Hi I have uploaded a file using reactjs and nodejs. Using the following code:

const tus = require('tus-node-server');
const serverFile = new tus.Server();
serverFile.datastore = new tus.FileStore({
    path: '/files'
});

const express = require('express');
const app = express();
const uploadApp = express();
uploadApp.all('*', serverFile.handle.bind(serverFile));
app.use('/uploads', uploadApp);

const host = '127.0.0.1';
const port = 9000;
app.listen(port, host);

And for the reactjs component:

<input type={'file'} onChange={(e) => {
    // Get the selected file from the input element
    var file = e.target.files[0]
    // Create a new tus upload
    var upload = new tus.Upload(file, {
      endpoint: "http://localhost:9000/uploads/",
      retryDelays: [0, 1000, 3000, 5000],
      metadata: {
        filename: file.name,
        filetype: file.type
      },
      onError: function(error) {
        console.log("Failed because: " + error)
      },
      onProgress: function(bytesUploaded, bytesTotal) {
        var percentage = (bytesUploaded / bytesTotal * 100).toFixed(2)
        console.log(bytesUploaded, bytesTotal, percentage + "%")
      },
      onSuccess: function() {
        console.log("Download %s from %s", upload.file.name, upload.url)
      }
    })
    // Start the upload
    upload.start()
}}/>

It uploads the file fine, however it doesn’t upload the file with the adequate extension? I am new to tus and was using other modules before this. Where am I going wrong? I am using serverFile as there is already another server specified in the file elsewhere: const server = require('http').Server(app);

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adrienfloorcommented, Feb 18, 2022

Awesome, thanks a lot @Acconut !

0reactions
Acconutcommented, Feb 16, 2022

@adrienfloor You need to put the content type into the metadata, like this:

var upload = new tus.Upload(file, {
      endpoint: "http://localhost:9000/uploads/",
      retryDelays: [0, 1000, 3000, 5000],
      metadata: {
        contentType: file.type
      },

See https://github.com/tus/tus-node-server/blob/2f800162e8ea6e60682f0bc62b8fe5597dbc17a9/lib/stores/S3Store.js#L138

Read more comments on GitHub >

github_iconTop Results From Across the Web

image extension is not showing in PHP file-upload
It works but there is one small thing that doesn't want to do its job. The extension that I'm trying to get is...
Read more >
Since Latest Mac OS, can no longer upload any files in Chrome
Since Latest Mac OS, can no longer upload any files in Chrome. I have disabled extensions as suggested. This does not work. I...
Read more >
Safari not opening "upload file" pop up w… - Apple Community
When I try to upload a file to a website, Safari won't open the pop up window to allow me to browse my...
Read more >
Uploading Browse feature doesn't display files in folder?
Am on a website, iPage, and want to upload a file to their FileManager. I use their Browse function to find and select...
Read more >
6800 - Chrome doesn't set Content-Type for file upload when ...
I get this on Chrome 7.0.517.44 and 8.0.552.215 when uploading a file with no extension. ... It works for the same file if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found