Bug Description
When trying to upload a file using the CLI tool, it throws a ReferenceError: File is not defined error. This is because the code tries to use the browser's File API which is not available in Node.js environment.
Steps to Reproduce
- Install the CLI tool
- Try to upload a file using the command:
shdw-drive upload \
--keypair ~/.config/solana/id_v2.json \
--bucket [bucket-id] \
--file path/to/file.gif
Error Message
Error uploading file: ReferenceError: File is not defined
at Command.<anonymous> (/Users/srm/dev/shdwdrive-v2-cli/dist/cli.js:41:22)
...
Current Implementation
In cli.ts, the code attempts to create a File object:
const fileBuffer = readFileSync(options.file);
const fileName = options.file.split('/').pop()!;
const file = new File([fileBuffer], fileName);
Suggested Fix
Consider using one of these approaches:
- Using form-data:
import FormData from 'form-data';
const fileBuffer = readFileSync(options.file);
const fileName = options.file.split('/').pop()!;
const formData = new FormData();
formData.append('file', fileBuffer, fileName);
- Or using Blob (Node.js v18.0.0+):
const fileBuffer = readFileSync(options.file);
const fileName = options.file.split('/').pop()!;
const blob = new Blob([fileBuffer], { type: 'application/octet-stream' });
Environment
- Node.js version: v18.17.0
- OS: macOS
- CLI version: latest from main branch
Would appreciate any guidance on which approach would be most suitable for the SDK's requirements.
Bug Description
When trying to upload a file using the CLI tool, it throws a
ReferenceError: File is not definederror. This is because the code tries to use the browser'sFileAPI which is not available in Node.js environment.Steps to Reproduce
shdw-drive upload \ --keypair ~/.config/solana/id_v2.json \ --bucket [bucket-id] \ --file path/to/file.gifError Message
Current Implementation
In cli.ts, the code attempts to create a File object:
Suggested Fix
Consider using one of these approaches:
Environment
Would appreciate any guidance on which approach would be most suitable for the SDK's requirements.