bee-js
bee-js copied to clipboard
file upload not working
i think bee-js file upload is not working. i cloned the ethersphere/examples-js and updated the bee-js to 6.4.0.
when i use the upload-react i get a bzzHash but if i try to open via browser the file/image is not found.
but it is working via swarm-desktop fileupload.
Hi, I have the same issue. It appears that the problem started with version 6.0.0 due to the change in the http library. When I revert to version 5.2.0, everything works. The issue appears with File upload, but String upload stills working well.
Here is the code I'm using in a Svelte environment:
import { Bee, FileUploadOptions } from "@ethersphere/bee-js";
import { DEFAULT_NAME } from "@lib/common/config";
import { swarmApiEndpoint, swarmApiKey, SWARM_ZERO_APIKEY } from "@lib/nft/storage/swarm";
const getBee = (nodeUrl: string): Bee => {
return new Bee(nodeUrl);
};
const swarmUploadFile = async (file: File | string): Promise<string> => {
const nodeUrl = swarmApiEndpoint();
const batchId = swarmApiKey();
const bee: Bee = getBee(nodeUrl);
const isFile = file instanceof File;
console.log("FILE : ", file);
const options: FileUploadOptions = {};
options.pin = true;
if (isFile && file?.size > 0) options.size = file.size;
if (isFile && file?.type) options.contentType = file.type;
const result = await bee.uploadFile(
batchId,
file,
isFile ? file.name : DEFAULT_NAME,
options
);
return result.reference;
};
export { swarmUploadFile };
This appears at page load :
And here is what i get after upload:
@savage9309 @dlaxcess can you try the latest bee-js v6.7.4 and see if this issue persists.
Oh it works much better now :)
Still have this error in console : Refused to set unsafe header "content-length"
but it seems that it doesn't prevent the upload.
Thx