tus / tus-js-client

A pure JavaScript client for the tus resumable upload protocol
https://tus.io/
MIT License
2.12k stars 316 forks source link

tus: invalid or missing Location header, originated from request #694

Open Kam205 opened 6 months ago

Kam205 commented 6 months ago

Describe the bug Whenever I try upload a file I am getting "tus: invalid or missing Location header, originated from request".

Failed because: tus: invalid or missing Location header, originated from request (method: POST, url: http://localhost:54321/storage/v1/object/filesupload/Gomathi Professional Development (1) (1).pdf, response code: 200, response text: {"Id":"88ea47f7-2522-4980-a259-f8072e4da259","Key":"filesupload/Gomathi Professional Development (1) (1).pdf"}, request id: n/a)

To Reproduce const upload = new tus.Upload(fileStream, { endpoint:${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/filesupload/${file.name}, retryDelays: [0, 3000, 5000, 10000, 20000], headers: { authorization: Bearer ${accessToken[1]}, 'x-upsert': 'true', // optionally set upsert to true to overwrite existing files "Content-Location" : ${process.env.NEXT_PUBLIC_SUPABASE_URL}/storage/v1/object/filesupload/${file.name}, location: uploadURl, }, uploadDataDuringCreation: true, uploadSize: fileBuffer.length, removeFingerprintOnSuccess: true, // Important if you want to allow re-uploading the same file https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess metadata: { bucketName: BUCKET_NAME, objectName: file.name, contentType: 'image/png',

    },
    chunkSize: 6 * 1024 * 1024, // NOTE: it must be set to 6MB (for now) do not change it
    onError: function (error) {
        console.log('Failed because: ' + error.message)
        reject(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, upload.url)
        resolve()
    },
})
 upload.start();
});
  1. Execute command '...'
  2. Start upload '...'
  3. See error

Please try to reproduce the problem when uploading to our public tus instance at https://tusd.tusdemo.net/files/, if applicable to your situation. This helps us to determine whether the problem may be caused by the server component.

Expected behavior File should uploaded.

Acconut commented 6 months ago

This is likely not a bug in tus-js-client but a configuration problem where the endpoint that you have defined is not a tus upload creation URL. Hence the response from the endpoint does not include the Location header as is expected from tus-js-client. You should double check the endpoint URL and have a look at Supabase's documentation. I haven't used their services and don't know their API.