fp/packages/next/app/uppy.tsx

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-01-20 16:16:14 +00:00
'use client';
import React, { useState, createContext, useContext, useEffect } from 'react';
import Uppy from '@uppy/core';
import AwsS3 from '@uppy/aws-s3';
import RemoteSources from '@uppy/remote-sources';
import { useAuth } from './components/auth';
2024-07-10 22:11:18 +00:00
import { companionUrl } from '@/app/lib/constants';
2024-01-20 16:16:14 +00:00
2024-07-06 08:49:51 +00:00
// Uppy is a challenging react integration. Following are some references
// @see https://github.com/transloadit/uppy/issues/4727#issuecomment-1761118428
2024-01-20 16:16:14 +00:00
export const UppyContext = createContext(new Uppy());
export default function UppyProvider({
children
}: {
children: React.ReactNode
}) {
const { authData } = useAuth();
2024-07-10 02:34:23 +00:00
const uppy = new Uppy(
// const [uppy] = useState(() => new Uppy(
{
autoProceed: true,
debug: true,
logger: {
debug: console.info,
warn: console.log,
error: console.error
},
2024-01-20 16:16:14 +00:00
}
)
.use(RemoteSources, {
companionUrl,
2024-07-10 02:34:23 +00:00
title: 'testing 123',
2024-01-20 16:16:14 +00:00
})
.use(AwsS3, {
companionUrl,
shouldUseMultipart: true,
abortMultipartUpload: () => {}, // @see https://github.com/transloadit/uppy/issues/1197#issuecomment-491756118
companionHeaders: {
'authorization': `Bearer ${authData?.accessToken}`
}
})
2024-07-10 02:34:23 +00:00
// );
2024-01-20 16:16:14 +00:00
return (
<UppyContext.Provider value={uppy}>
{children}
</UppyContext.Provider>
)
}