question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

It seems that this url cannot be inserted into the img tag

See original GitHub issue

this is the uploadImages code

uploadImages={async (files) => {
            return await uploadImges(files);
          }}

this is the my uplload and download code

export async function upload(files) {
  let formData = new FormData();
  formData.append("files[]", files);
  let res = await axios.post("/file/upload", formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
  if (res.data.stat === "ok") {
    return res.data.data;
  } else {
    return null;
  }
}

export async function download(key) {
  let res = await axios.get(`/file/download/${key}`, {
    responseType: "blob",
  });
  let blob = new Blob([res.data]);
  return window.URL.createObjectURL(blob);
}

interface Pick {
  alt: string;
  title: string;
  url: string;
}

export async function uploadImges(files) {
  let imgs: Pick[] = [];
  for (let file of files) {
    let key = await upload(file);
    let url = await download(key);
    console.log(url);
    let img: Pick = {
      alt: "img",
      title: "img",
      url: url,
    };
    imgs.push(img);
  }
  return imgs;
}

because the sever code is fixed ,I can only use the method to upload image and download

image image

As you can see, the src of the picture is empty

Maybe I used it wrong, please help me, I will be very grateful

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ducaoyacommented, Aug 26, 2021

Thank you . Your suggestion is very useful, and I have gained a lot.

0reactions
zhanggujuncommented, Dec 26, 2022
  const sanitize = schema => {
    schema.protocols.src.push('blob')
    return schema
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML <img> tag is not working - Stack Overflow
Check that JPG file extension is uppercase in the file system. I suspect that it is lowercase. Also be sure to close the...
Read more >
A 4-Minute Guide to the Img src Attribute in HTML
The source attribute contains the path to the image file or its URL. That explains why images are technically linked to — not...
Read more >
<img>: The Image Embed element - HTML - MDN Web Docs
The HTML element embeds an image into the document. ... The src URL is the same as the URL of the page the...
Read more >
How to handle loading of images that may not exist?
An image URL that is incorrect or points to an image that no longer exists, is most likely a data issue. So the...
Read more >
you can't insert a site-local image URL · Issue #20903 - GitHub
I want to insert existing images on my web site, i.e. the img src attribute for them will be /path/to/image.jpg .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found