You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Summary:
Experiencing a 500 Internal Server Error when making requests to the Web3.Storage API, both during file upload and while retrieving CIDs.
Details:
Initial Request:
When the getCIDs function is called initially, it receives a status of 200 OK.
Upload Attempt:
Using the handler function along with uploadToWeb3Storage fails intermittently. No error, but got an authorization message. Then fixed the authorization by adding store/add, then tried again, and got 500 Internal Server Error.
Subsequent Requests:
After a failed upload attempt, subsequent requests to getCIDs also return a 500 Internal Server Error.
Code Behavior:
The uploadToWeb3Storage function creates a CAR file and sends a JSON payload to https://up.web3.storage/bridge.
The getCIDs function attempts to get a list of CIDs from the same endpoint.
working code:
import{createFileEncoderStream,CAREncoderStream}from'ipfs-car';import{Blob}from'buffer';importaxiosfrom'axios';importdotenvfrom'dotenv';importexpressfrom'express';importfsfrom'fs';importmulterfrom'multer';constapp=express();constport=process.env.PORT||4000;constupload=multer();dotenv.config({path: '.env'});asyncfunctionuploadToWeb3Storage(fileBuffer,spaceKey,authSecret,authToken){constfile=newBlob([fileBuffer],{type: 'application/octet-stream'});letrootCID;constchunks=[];awaitcreateFileEncoderStream(file).pipeThrough(newTransformStream({transform(block,controller){rootCID=block.cid;controller.enqueue(block);}})).pipeThrough(newCAREncoderStream()).pipeTo(newWritableStream({write(chunk){chunks.push(chunk);}}));constcarBuffer=newUint8Array(chunks.reduce((acc,chunk)=>acc+chunk.length,0));letoffset=0;for(constchunkofchunks){carBuffer.set(chunk,offset);offset+=chunk.length;}constcarSize=carBuffer.length;conststoreJson={tasks: [["upload/add",spaceKey,{link: {"/": rootCID.toString()},size: carSize}]]};try{constresponse=awaitaxios.post('https://up.web3.storage/bridge',storeJson,{headers: {'X-Auth-Secret': authSecret,'Authorization': authToken,'Content-Type': 'application/json'}});console.log('Upload successful. Response:',response.data);returnresponse.data;}catch(error){console.error('Upload failed:',error.response ? error.response.data : error.message);throwerror;}}exportasyncfunctionhandler(fileBuffer){constW3S_SPACE=process.env.W3S_SPACE;constX_AUTH_SECRET=process.env.X_AUTH_SECRET;constAUTH_HEADER=process.env.AUTH_HEADER;try{constresult=awaituploadToWeb3Storage(fileBuffer,W3S_SPACE,X_AUTH_SECRET,AUTH_HEADER);return{statusCode: 200,body: JSON.stringify(result)};}catch(error){return{statusCode: 500,body: JSON.stringify({error: error.message})};}}app.post('/upload',upload.single('file'),async(req,res)=>{try{constfileBuffer=req.file.buffer;constcarFile=awaithandler(fileBuffer);res.status(200).json({ carFile });}catch(err){console.error('Error creating CAR file:',err);res.status(500).send('Error creating CAR file');}});app.listen(port,()=>{console.log(`Server running on port ${port}`);});constgetCIDs=async()=>{constX_AUTH_SECRET=process.env.X_AUTH_SECRET;constAUTH_HEADER=process.env.AUTH_HEADER;constW3S_SPACE=process.env.W3S_SPACE;try{constresponse=awaitaxios.post('https://up.web3.storage/bridge',{"tasks": [["store/list",W3S_SPACE,{}]]},{headers: {'X-Auth-Secret': X_AUTH_SECRET,'Authorization': AUTH_HEADER}});console.log('data-p-fx: ',response.data[0].p.fx);console.log('data-p-out: ',response.data[0].p.out);console.log('data-p-ran: ',response.data[0].p.ran);console.log('data-s: ',response.data[0].s['/']);}catch(error){console.error('Failed to retrieve CIDs:',error.message);}};getCIDs().then(()=>console.log('done')).catch((error)=>console.log(error));
Error Log:
500 Internal Server Error on upload attempts and when calling getCIDs.
Possible Causes:
Issues with the Web3.Storage API.
Problems with the JSON payload or headers being sent.
Server-side issues with the Web3.Storage service.
Actions Taken:
Verified payload structure and headers.
Tried multiple requests resulting in consistent 500 errors.
Request for Assistance:
Diagnose the cause of the 500 Internal Server Error from the Web3.Storage API.
Confirm if there are known issues with the Web3.Storage API or if there's a need for adjustments in the request format or payload.
The text was updated successfully, but these errors were encountered:
Issue Description
Summary:
Experiencing a
500 Internal Server Error
when making requests to the Web3.Storage API, both during file upload and while retrieving CIDs.Details:
Initial Request:
getCIDs
function is called initially, it receives a status of200 OK
.Upload Attempt:
handler
function along withuploadToWeb3Storage
fails intermittently. No error, but got an authorization message. Then fixed the authorization by addingstore/add
, then tried again, and got500 Internal Server Error
.Subsequent Requests:
getCIDs
also return a500 Internal Server Error
.Code Behavior:
uploadToWeb3Storage
function creates a CAR file and sends a JSON payload tohttps://up.web3.storage/bridge
.getCIDs
function attempts to get a list of CIDs from the same endpoint.working code:
Error Log:
500 Internal Server Error
on upload attempts and when callinggetCIDs
.Possible Causes:
Actions Taken:
500
errors.Request for Assistance:
500 Internal Server Error
from the Web3.Storage API.The text was updated successfully, but these errors were encountered: