so I want to upload the test JSON to arweave. The appending of transaction and env works fine, but when I try to append bufferTest I get this error
Unhandled Rejection (TypeError): Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.
I tried doing: data.append('file[]', new Blob(bufferTest), 'metadata.json');, but then it just uploads the Buffer values in UTF8 like this: 1.2334116101115117e+39.
I literally just copied this from Metaplex candy-machine-v2. They also just append the Buffer.
I don't know if this has something to do with React or me just being stupid.
const test = { "test": "test" };
const bufferTest: any = Buffer.from(JSON.stringify(test)); //metadata as buffer
export default function Test(props:any){
//...
const data = new FormData();
data.append('transaction', txID!); // Transaction ID
data.append('env', env); // env = devnet
data.append('file[]', bufferTest, 'metadata.json');
const result = await upload(data);
//...
}
async function upload(data: FormData) {
return await (
await fetch(ARWEAVE_UPLOAD_ENDPOINT, {
method: 'POST',
// @ts-ignore
body: data,
})
).json();
}
you need to put a for loop on all files selected inside the input file like the bellow :
var len = document.getElementById('XXXX').files.length;
for (var i = 0; i < len ; i++) {
fd.append("file[]", document.getElementById('XXXX').files[i]);
}
let me know if it's working