Uppy OneDrive not working

Started by pankaj.sharma1 reply71 views
pankaj.sharmaOriginal post
#1

I am new to the Uppy file uploader and want to upload files from various sources like OneDrive and Google Drive. I have created an application on Azure with the redirect URL set to http://localhost:3020/companion/onedrive/redirect, but it is not working.

Below is my server.js code
const express = require(‘express’)
const bodyParser = require(‘body-parser’)
const session = require(‘express-session’)
const companion = require(‘@uppy/companion’)

const app = express()

// Session middleware
//const sess = session({
// secret: ‘some-secret1’,
// resave: true,
// saveUninitialized: true,
//})

// Apply session middleware
//app.use(sess)

app.use(bodyParser.json())

app.use((req, res, next) =>
{
res.setHeader(‘Access-Control-Allow-Origin’, req.headers.origin || ‘*’)
next()
})

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

const companionOptions = {
providerOptions: {
onedrive: {
key: CLIENT_KEY,
secret: SECRET_SECRET,
redirectUri: redirectUri goes here,
}
},
server: {
host: ‘localhost:3020’,
protocol: ‘http’,
},
filePath: ‘./output’,
secret: ‘some-secret’,
debug: true,
//sessionMiddleware: sess,
}

const { app: companionApp } = companion.app(companionOptions)
app.use(‘/companion’, companionApp);

// Error & 404 handling
app.use((req, res) =>
{
debugger;
return res.status(404).json({ message: ‘Not Found’ })
})

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

// Start server and bind sockets
const server = app.listen(3020, () =>
{
console.log(‘Welcome to Companion!’)
console.log(‘Listening on http://localhost:3020’)
})

companion.socket(server)

And below is my client-side code

const { Uppy, Dashboard, XHRUpload, OneDrive } = window.Uppy;

const uppy = new Uppy({
restrictions: {
maxNumberOfFiles: null,
//allowedFileTypes: [“.jpg”, “.jpeg”, “.png”, “.gif”, “.webp”]
},
autoProceed: false,
debug: true
});

uppy.use(Dashboard, {
inline: true,
target: ‘#uppyExample’,
// note: ‘Upload as many files as you like’,
showProgressDetails: true,
proudlyDisplayPoweredByUppy: false,
browserBackButtonClose: false,
})

uppy.use(OneDrive, {
target: Dashboard,
companionUrl: companionUrl,
//companionKeysParams: {
// uppyVersions: ‘@uppy/core@4.12.2 @uppy/onedrive@4.4.0’
//},
companionHeaders: () =>
{
console.log(‘Plugin config loaded correctly’);
return {};
}
});

But the above code is not working.

Getting the following error in the console when clicking on the OneDrive icon getting 400 (Bad Request)

pankaj.sharma
#2

Please help me understand why the issue above is not working and where I might be going wrong. I have configured everything as mentioned in the documentation. I have attached a screenshot of the output screen that appears when I click on “Connect to OneDrive”. I am getting the same error when I click on “Connect to Google Drive” as well