How to convert Base64 String to javascript file object like as from file input form?

后端 未结 5 1193
忘了有多久
忘了有多久 2020-11-28 06:43

I want to convert Base64String extracted from file(ex: \"AAAAA....~\") to a javascript file object.

The javascript file object what I mean is like this code:

<
5条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 07:17

    const url = 'data:image/png;base6....';
    fetch(url)
      .then(res => res.blob())
      .then(blob => {
        const file = new File([blob], "File name",{ type: "image/png" })
      })
    

    Base64 String -> Blob -> File.

提交回复
热议问题