bee-js icon indicating copy to clipboard operation
bee-js copied to clipboard

file upload not working

Open savage9309 opened this issue 1 year ago • 3 comments

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. Screenshot 2023-09-08 at 11 28 22

savage9309 avatar Sep 08 '23 11:09 savage9309

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 : Capture d’écran du 2023-09-23 17-00-59

And here is what i get after upload: Capture d’écran du 2023-09-23 17-14-41

dlaxcess avatar Sep 23 '23 15:09 dlaxcess

@savage9309 @dlaxcess can you try the latest bee-js v6.7.4 and see if this issue persists.

rampall avatar Feb 27 '24 11:02 rampall

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

dlaxcess avatar Feb 27 '24 19:02 dlaxcess