web3-storage / web3.storage

DEPRECATED ⁂ The simple file storage service for IPFS & Filecoin
https://web3.storage
Other
503 stars 119 forks source link

error when uploading file from nodejs online server #1645

Closed elishaakande closed 2 years ago

elishaakande commented 2 years ago

the code work when I upload from local host but as soon as I push to live server I keep getting satus 500 error

export const uploadFile = async(req, res) => {
   const client = new Web3Storage({ token: process.env.WEB3_STORAGE })
    const base64 = req.body.file
    const fileName = req.body.filename
    const fileBuffer = Buffer.from(base64, 'base64')

    try {
            await writeFileSync(req.body.filename, fileBuffer);
            // Pack files into a CAR and send to web3.storage
            const file = await getFilesFromPath(req.body.filename);
            const rootCid = await client.put(file);
            // Get info on the Filecoin deals that the CID is stored in
            const info = await client.status(rootCid) // Promise<Status | undefined>
            await unlinkSync(req.body.filename)
            res.status(200).json(info.cid+".ipfs.dweb.link/"+fileName)
        } catch (error) {
            res.status(500).json(error)
        }
}

when I try debugging the error, I think it's coming from const rootCid

elishaakande commented 2 years ago

this issue is from gitignore