uploadFileToArweave does not work with Buffer
elliotBraem opened this issue · 5 comments
I'm uploading metadata to form as the reference for a mint. For example:
const metadata = Buffer.from(JSON.stringify({
extra: "sample"
}));
const response = await uploadFileToArweave(metadata, "sample-name");
const url = `https://arweave.net/${response.id}`;
If I run this, I will get the following exception, which is misleading because the actual exception being thrown does not work with httpError.response.text:
Cannot read properties of undefined (reading 'text')
The actual exception is:
Failed to execute 'append' on 'FormData': parameter 2 is not of type 'Blob'.
I think somebody just needs to wrap the buffer in "new Blob([buffer])". Wasn't caught because append function is mocked in test.
I now recall quickly authoring this function and we actually aren't using it anywhere yet. As you point out, this could use an integration test.
Would you mind confirming the environment you're running this in, including node version if server side?
I'm looking at the integration tests run against the service which are passing and don't wrap the buffer in Blob, so I wonder if env changes how superagent/supertest is treating the bytes under the hood 🤔
Oh interesting; I’m using this client side and this happened in development, but the same error is happening in my production build as well.
This is all I’m doing:
export async function mintThing(thingId: string, args: CreateThingBlockchainArgs): Promise<void | FinalExecutionOutcome> {
if (!isUuid(thingId)) {
throw new Error(NOT_VALID_UUID);
}
const metadata = Buffer.from(JSON.stringify({
extra: thingId
}));
const response = await uploadFileToArweave(metadata, thingId);
Creating an object with a single field, making it a JSON, turning into Buffer, passing to function.
Passing File has been working for me, Buffer is not. Super strange about that integration test...
The integration tests are all run in node, so I am guessing this has to do with the browser env. Someday, we hope to have test automation in the packages/app browser test suite, but until then we can do a manual test there and be sure this works with client side JSON. Have you attempted to upload from File
as well? That is also on the list, so maybe we can do it in a single PR
@elliotBraem looks like @microchipgnu has created a draft with starting point for the browser based upload function: #223
We are short staffed this week, but will work on some final testing and documentation and get this merged ASAP.
If you would like to give any feedback on the PR we'd love that, one of the many goals of our grants program is open source participation.
Closing this now that we have merged a browser based example. Please feel free to re open this issue or create a new one @elliotBraem if you have problems specific to browser upload.