2

I use a React component that converts an image to a blob URL. The URL looks like this: "blob:http://localhost:3000/78db8897-645d-4323-8865-8deaa9716a96". Appending it to a works, it shows the image. But I want to be able to upload this string to the server as the file. I have a function I found here on SO but it doesn't work.

export function blobToFile(blobUrl, fileName) {
  const blob = new Blob([blobUrl], {
    lastModifiedDate: Date.now(),
    type: "image/png",
  });

  const file = new File([blob], fileName + ".png", {
    type: "image/png",
    lastModified: Date.now(),
  });
  return file;
}

6
  • do you see any errors in the debugging console? Commented Jan 9, 2021 at 17:43
  • no i dont see any errors. the file gets uploaded, but when i open it with my operating system, it doesnt open. so the conversion is wrong Commented Jan 9, 2021 at 17:47
  • is this supposed to work? i think the problem is with the blobUrl to Blob function Commented Jan 9, 2021 at 18:15
  • Have you googled yet? I searched and found two good posts here and here that might help you. Otherwise, more information would be useful: Which browser do you use? Which version? Commented Jan 9, 2021 at 18:19
  • i figured it out. i found an answer on a chinese website lol Commented Jan 10, 2021 at 16:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.